ListCommand.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Command;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputOption;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\Console\Output\Output;
  16. use Symfony\Component\Console\Command\Command;
  17. /**
  18. * ListCommand displays the list of all available commands for the application.
  19. *
  20. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  21. */
  22. class ListCommand extends Command
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function configure()
  28. {
  29. $this
  30. ->setDefinition(array(
  31. new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
  32. new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
  33. ))
  34. ->setName('list')
  35. ->setDescription('Lists commands')
  36. ->setHelp(<<<EOF
  37. The <info>list</info> command lists all commands:
  38. <info>./symfony list</info>
  39. You can also display the commands for a specific namespace:
  40. <info>./symfony list test</info>
  41. You can also output the information as XML by using the <comment>--xml</comment> option:
  42. <info>./symfony list --xml</info>
  43. EOF
  44. );
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. protected function execute(InputInterface $input, OutputInterface $output)
  50. {
  51. if ($input->getOption('xml')) {
  52. $output->writeln($this->application->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW);
  53. } else {
  54. $output->writeln($this->application->asText($input->getArgument('namespace')));
  55. }
  56. }
  57. }