You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.3 KiB

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