No Description

ListCommand.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Helper\DescriptorHelper;
  12. use Symfony\Component\Console\Input\InputArgument;
  13. use Symfony\Component\Console\Input\InputDefinition;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Input\InputOption;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. /**
  18. * ListCommand displays the list of all available commands for the application.
  19. *
  20. * @author Fabien Potencier <fabien@symfony.com>
  21. */
  22. class ListCommand extends Command
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function configure()
  28. {
  29. $this
  30. ->setName('list')
  31. ->setDefinition($this->createDefinition())
  32. ->setDescription('List commands')
  33. ->setHelp(<<<'EOF'
  34. The <info>%command.name%</info> command lists all commands:
  35. <info>php %command.full_name%</info>
  36. You can also display the commands for a specific namespace:
  37. <info>php %command.full_name% test</info>
  38. You can also output the information in other formats by using the <comment>--format</comment> option:
  39. <info>php %command.full_name% --format=xml</info>
  40. It's also possible to get raw list of commands (useful for embedding command runner):
  41. <info>php %command.full_name% --raw</info>
  42. EOF
  43. )
  44. ;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function getNativeDefinition()
  50. {
  51. return $this->createDefinition();
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. protected function execute(InputInterface $input, OutputInterface $output)
  57. {
  58. $helper = new DescriptorHelper();
  59. $helper->describe($output, $this->getApplication(), [
  60. 'format' => $input->getOption('format'),
  61. 'raw_text' => $input->getOption('raw'),
  62. 'namespace' => $input->getArgument('namespace'),
  63. ]);
  64. return 0;
  65. }
  66. private function createDefinition(): InputDefinition
  67. {
  68. return new InputDefinition([
  69. new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
  70. new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
  71. new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
  72. ]);
  73. }
  74. }