Book Image

Magento 2 Development Cookbook

Book Image

Magento 2 Development Cookbook

Overview of this book

With the challenges of growing an online business, Magento 2 is an open source e-commerce platform with innumerable functionalities that gives you the freedom to make on-the-fly decisions. It allows you to customize multiple levels of security permissions and enhance the look and feel of your website, and thus gives you a personalized experience in promoting your business.
Table of Contents (18 chapters)
Magento 2 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. 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...