4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Command;
14 use Symfony\Component\Console\Helper\DescriptorHelper;
15 use Symfony\Component\Console\Input\InputArgument;
16 use Symfony\Component\Console\Input\InputOption;
17 use Symfony\Component\Console\Input\InputInterface;
18 use Symfony\Component\Console\Output\OutputInterface;
21 * HelpCommand displays the help for a given command.
23 * @author Fabien Potencier <fabien@symfony.com>
25 class HelpCommand extends Command
32 protected function configure()
34 $this->ignoreValidationErrors();
38 ->setDefinition(array(
39 new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
40 new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
41 new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
43 ->setDescription('Displays help for a command')
45 The <info>%command.name%</info> command displays help for a given command:
47 <info>php %command.full_name% list</info>
49 You can also output the help in other formats by using the <comment>--format</comment> option:
51 <info>php %command.full_name% --format=xml list</info>
53 To display the list of available commands, please use the <info>list</info> command.
59 public function setCommand(Command $command)
61 $this->command = $command;
67 protected function execute(InputInterface $input, OutputInterface $output)
69 if (null === $this->command) {
70 $this->command = $this->getApplication()->find($input->getArgument('command_name'));
73 $helper = new DescriptorHelper();
74 $helper->describe($output, $this->command, array(
75 'format' => $input->getOption('format'),
76 'raw_text' => $input->getOption('raw'),
79 $this->command = null;