FooOptCommand.php 967 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. use Symfony\Component\Console\Command\Command;
  3. use Symfony\Component\Console\Input\InputInterface;
  4. use Symfony\Component\Console\Input\InputOption;
  5. use Symfony\Component\Console\Output\OutputInterface;
  6. class FooOptCommand extends Command
  7. {
  8. public $input;
  9. public $output;
  10. protected function configure()
  11. {
  12. $this
  13. ->setName('foo:bar')
  14. ->setDescription('The foo:bar command')
  15. ->setAliases(['afoobar'])
  16. ->addOption('fooopt', 'fo', InputOption::VALUE_OPTIONAL, 'fooopt description')
  17. ;
  18. }
  19. protected function interact(InputInterface $input, OutputInterface $output)
  20. {
  21. $output->writeln('interact called');
  22. }
  23. protected function execute(InputInterface $input, OutputInterface $output)
  24. {
  25. $this->input = $input;
  26. $this->output = $output;
  27. $output->writeln('called');
  28. $output->writeln($this->input->getOption('fooopt'));
  29. }
  30. }