O'Reilly logo

Magento 2 - Build World-Class online stores by Jonathan Bownds, Bret Williams, Vladimir Kerkhoff, Ray Bogman, Fernando J. Miguel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. Create the AddCommand class; this is used ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required