annotate vendor/symfony/console/Command/ListCommand.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\Console\Command;
Chris@0 13
Chris@0 14 use Symfony\Component\Console\Helper\DescriptorHelper;
Chris@0 15 use Symfony\Component\Console\Input\InputArgument;
Chris@17 16 use Symfony\Component\Console\Input\InputDefinition;
Chris@17 17 use Symfony\Component\Console\Input\InputInterface;
Chris@0 18 use Symfony\Component\Console\Input\InputOption;
Chris@0 19 use Symfony\Component\Console\Output\OutputInterface;
Chris@0 20
Chris@0 21 /**
Chris@0 22 * ListCommand displays the list of all available commands for the application.
Chris@0 23 *
Chris@0 24 * @author Fabien Potencier <fabien@symfony.com>
Chris@0 25 */
Chris@0 26 class ListCommand extends Command
Chris@0 27 {
Chris@0 28 /**
Chris@0 29 * {@inheritdoc}
Chris@0 30 */
Chris@0 31 protected function configure()
Chris@0 32 {
Chris@0 33 $this
Chris@0 34 ->setName('list')
Chris@0 35 ->setDefinition($this->createDefinition())
Chris@0 36 ->setDescription('Lists commands')
Chris@0 37 ->setHelp(<<<'EOF'
Chris@0 38 The <info>%command.name%</info> command lists all commands:
Chris@0 39
Chris@0 40 <info>php %command.full_name%</info>
Chris@0 41
Chris@0 42 You can also display the commands for a specific namespace:
Chris@0 43
Chris@0 44 <info>php %command.full_name% test</info>
Chris@0 45
Chris@0 46 You can also output the information in other formats by using the <comment>--format</comment> option:
Chris@0 47
Chris@0 48 <info>php %command.full_name% --format=xml</info>
Chris@0 49
Chris@0 50 It's also possible to get raw list of commands (useful for embedding command runner):
Chris@0 51
Chris@0 52 <info>php %command.full_name% --raw</info>
Chris@0 53 EOF
Chris@0 54 )
Chris@0 55 ;
Chris@0 56 }
Chris@0 57
Chris@0 58 /**
Chris@0 59 * {@inheritdoc}
Chris@0 60 */
Chris@0 61 public function getNativeDefinition()
Chris@0 62 {
Chris@0 63 return $this->createDefinition();
Chris@0 64 }
Chris@0 65
Chris@0 66 /**
Chris@0 67 * {@inheritdoc}
Chris@0 68 */
Chris@0 69 protected function execute(InputInterface $input, OutputInterface $output)
Chris@0 70 {
Chris@0 71 $helper = new DescriptorHelper();
Chris@17 72 $helper->describe($output, $this->getApplication(), [
Chris@0 73 'format' => $input->getOption('format'),
Chris@0 74 'raw_text' => $input->getOption('raw'),
Chris@0 75 'namespace' => $input->getArgument('namespace'),
Chris@17 76 ]);
Chris@0 77 }
Chris@0 78
Chris@0 79 /**
Chris@0 80 * {@inheritdoc}
Chris@0 81 */
Chris@0 82 private function createDefinition()
Chris@0 83 {
Chris@17 84 return new InputDefinition([
Chris@0 85 new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
Chris@0 86 new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
Chris@0 87 new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
Chris@17 88 ]);
Chris@0 89 }
Chris@0 90 }