AnnotatedGreetCommand.php

Namespace

Drupal\woot\Command

Classes

Namesort descending Description
AnnotatedGreetCommand This is an annotated version of the example Symfony Console command from the documentation.

File

tests/resources/modules/d8/woot/src/Command/AnnotatedGreetCommand.php
View source
  1. <?php
  2. namespace Drupal\woot\Command;
  3. use Consolidation\AnnotatedCommand\AnnotatedCommand;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Input\InputOption;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. /**
  10. * This is an annotated version of the example Symfony Console command
  11. * from the documentation.
  12. *
  13. * See: http://symfony.com/doc/2.7/components/console/introduction.html#creating-a-basic-command
  14. */
  15. class AnnotatedGreetCommand extends AnnotatedCommand
  16. {
  17. /**
  18. * Greet someone
  19. *
  20. * @command annotated:greet
  21. * @arg string $name Who do you want to greet?
  22. * @option boolean $yell If set, the task will yell in uppercase letters
  23. */
  24. protected function execute(InputInterface $input, OutputInterface $output)
  25. {
  26. $name = $input->getArgument('name');
  27. if ($name) {
  28. $text = 'Hello '.$name;
  29. } else {
  30. $text = 'Hello';
  31. }
  32. if ($input->getOption('yell')) {
  33. $text = strtoupper($text);
  34. }
  35. $output->writeln($text);
  36. }
  37. }