Adding a console command
Another new thing in Magento 2 is the built-in command-line tool. In this chapter, we used this tool to clean the cache, for example.
Within a module, it is possible to extend this tool with custom commands, and this is the thing that we will do in this recipe.
Getting ready
This recipe will build further on the module that we have created in this chapter. If you don't have the code, you can install the starter files.
How to do it...
In the next steps, we will create a simple console command that will print some output to the console. Using this principle, you can create your own commands to automate some tasks:
For a custom console command, we have to add the following configuration in the
di.xml
file of the module. Paste the following code in that file as child of the<config>
tag:<type name="Magento\Framework\Console\CommandList"> <arguments> <argument name="commands" xsi:type="array"> <item name="helloWorldCommand...