class GreetCommand

This is a literal copy of the example Symfony Console command from the documentation.

See: http://symfony.com/doc/2.7/components/console/introduction.html#creating...

Namespace

Drupal\woot\Command

Hierarchy

  • class GreetCommand extends \Symfony\Component\Console\Command\Command

Expanded class hierarchy of GreetCommand

Members

Contains filters are case sensitive

File

tests/resources/modules/d8/woot/src/Command/GreetCommand.php, line 16

View source
class GreetCommand extends Command {
  protected function configure() {
    $this->setName('demo:greet')->setDescription('Greet someone')->addArgument('name', InputArgument::OPTIONAL, 'Who do you want to greet?')->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters');
  }

  protected function execute(InputInterface $input, OutputInterface $output) {
    $name = $input->getArgument('name');
    if ($name) {
      $text = 'Hello ' . $name;
    }
    else {
      $text = 'Hello';
    }

    if ($input->getOption('yell')) {
      $text = strtoupper($text);
    }

    $output->writeln($text);
  }
}