annotate vendor/symfony/console/Command/HelpCommand.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\InputInterface;
Chris@0 17 use Symfony\Component\Console\Input\InputOption;
Chris@0 18 use Symfony\Component\Console\Output\OutputInterface;
Chris@0 19
Chris@0 20 /**
Chris@0 21 * HelpCommand displays the help for a given command.
Chris@0 22 *
Chris@0 23 * @author Fabien Potencier <fabien@symfony.com>
Chris@0 24 */
Chris@0 25 class HelpCommand extends Command
Chris@0 26 {
Chris@0 27 private $command;
Chris@0 28
Chris@0 29 /**
Chris@0 30 * {@inheritdoc}
Chris@0 31 */
Chris@0 32 protected function configure()
Chris@0 33 {
Chris@0 34 $this->ignoreValidationErrors();
Chris@0 35
Chris@0 36 $this
Chris@0 37 ->setName('help')
Chris@17 38 ->setDefinition([
Chris@0 39 new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
Chris@0 40 new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
Chris@0 41 new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
Chris@17 42 ])
Chris@0 43 ->setDescription('Displays help for a command')
Chris@0 44 ->setHelp(<<<'EOF'
Chris@0 45 The <info>%command.name%</info> command displays help for a given command:
Chris@0 46
Chris@0 47 <info>php %command.full_name% list</info>
Chris@0 48
Chris@0 49 You can also output the help in other formats by using the <comment>--format</comment> option:
Chris@0 50
Chris@0 51 <info>php %command.full_name% --format=xml list</info>
Chris@0 52
Chris@0 53 To display the list of available commands, please use the <info>list</info> command.
Chris@0 54 EOF
Chris@0 55 )
Chris@0 56 ;
Chris@0 57 }
Chris@0 58
Chris@0 59 public function setCommand(Command $command)
Chris@0 60 {
Chris@0 61 $this->command = $command;
Chris@0 62 }
Chris@0 63
Chris@0 64 /**
Chris@0 65 * {@inheritdoc}
Chris@0 66 */
Chris@0 67 protected function execute(InputInterface $input, OutputInterface $output)
Chris@0 68 {
Chris@0 69 if (null === $this->command) {
Chris@0 70 $this->command = $this->getApplication()->find($input->getArgument('command_name'));
Chris@0 71 }
Chris@0 72
Chris@0 73 $helper = new DescriptorHelper();
Chris@17 74 $helper->describe($output, $this->command, [
Chris@0 75 'format' => $input->getOption('format'),
Chris@0 76 'raw_text' => $input->getOption('raw'),
Chris@17 77 ]);
Chris@0 78
Chris@0 79 $this->command = null;
Chris@0 80 }
Chris@0 81 }