5 * Contains \Drupal\Console\Develop\Example.
8 namespace Drupal\Console\Command\Develop;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Console\Core\Command\Shared\CommandTrait;
14 use Drupal\Console\Core\Style\DrupalStyle;
17 * Class ExampleCommand
19 * @package Drupal\Console\Command\Develop
21 class ExampleCommand extends Command
29 * ExampleCommand constructor.
31 public function __construct()
33 parent::__construct();
36 protected function configure()
38 $this->setName('develop:example');
44 protected function interact(InputInterface $input, OutputInterface $output)
51 protected function execute(InputInterface $input, OutputInterface $output)
53 /* Register your command as a service
55 * Make sure you register your command class at
56 * config/services/namespace.yml file and add the `drupal.command` tag.
59 * class: Drupal\Console\Command\Develop\ExampleCommand
60 * arguments: ['@service_id', '@console.service_id']
62 * - { name: drupal.command }
64 * NOTE: Make the proper changes on the namespace and class
65 * according your new command.
67 * DrupalConsole extends the SymfonyStyle class to provide
68 * an standardized Output Formatting Style.
70 * Drupal Console provides the DrupalStyle helper class:
72 $io = new DrupalStyle($input, $output);
73 $io->simple('This text could be translatable by');
74 $io->simple('adding a YAML file at "config/translations/LANGUAGE/command.name.yml"');
77 * Reading user input argument
78 * $input->getArgument('ARGUMENT_NAME');
80 * Reading user input option
81 * $input->getOption('OPTION_NAME');