GreetCommand.php

Namespace

Drupal\woot\Command

Classes

Namesort descending Description
GreetCommand This is a literal copy of the example Symfony Console command from the documentation.

File

tests/resources/modules/d8/woot/src/Command/GreetCommand.php
View source
  1. <?php
  2. namespace Drupal\woot\Command;
  3. use Symfony\Component\Console\Command\Command;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Input\InputOption;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. /**
  9. * This is a literal copy of the example Symfony Console command
  10. * from the documentation.
  11. *
  12. * See: http://symfony.com/doc/2.7/components/console/introduction.html#creating-a-basic-command
  13. */
  14. class GreetCommand extends Command
  15. {
  16. protected function configure()
  17. {
  18. $this
  19. ->setName('demo:greet')
  20. ->setDescription('Greet someone')
  21. ->addArgument(
  22. 'name',
  23. InputArgument::OPTIONAL,
  24. 'Who do you want to greet?'
  25. )
  26. ->addOption(
  27. 'yell',
  28. null,
  29. InputOption::VALUE_NONE,
  30. 'If set, the task will yell in uppercase letters'
  31. )
  32. ;
  33. }
  34. protected function execute(InputInterface $input, OutputInterface $output)
  35. {
  36. $name = $input->getArgument('name');
  37. if ($name) {
  38. $text = 'Hello '.$name;
  39. } else {
  40. $text = 'Hello';
  41. }
  42. if ($input->getOption('yell')) {
  43. $text = strtoupper($text);
  44. }
  45. $output->writeln($text);
  46. }
  47. }