Creating a Magento CLI command option
With Magento 2, there is a command-line interface (CLI) available to run several tasks. The bin/magento
command replaces the separate shell scripts that were used in Magento 1. This command is based on the Symfony Console component and looks just like n98-magerun
that is available for Magento 1. Just like the rest of Magento 2, it's possible to extend the CLI tool with your own commands.
Getting ready
Adding commands to the CLI script requires some knowledge of the Symfony Console component. This recipe also uses the service layer created in the previous recipe.
How to do itβ¦
In this recipe, we will add four options to the bin/magento
CLI command with the following steps:
Create the
AddCommand
class; this is used to create a new record through the CLI:Console/Command/AddCommand.php
<?php namespace Genmato\Sample\Console\Command; use Genmato\Sample\Api\DemoRepositoryInterface; use Genmato\Sample\Model\Data\DemoFactory; use Genmato\Sample\Api\Data\DemoInterface...