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('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
41 new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
42 new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
44 ->setDescription('Displays help for a command')
46 The <info>%command.name%</info> command displays help for a given command:
48 <info>php %command.full_name% list</info>
50 You can also output the help in other formats by using the <comment>--format</comment> option:
52 <info>php %command.full_name% --format=xml list</info>
54 To display the list of available commands, please use the <info>list</info> command.
63 * @param Command $command The command to set
65 public function setCommand(Command $command)
67 $this->command = $command;
73 protected function execute(InputInterface $input, OutputInterface $output)
75 if (null === $this->command) {
76 $this->command = $this->getApplication()->find($input->getArgument('command_name'));
79 if ($input->getOption('xml')) {
80 @trigger_error('The --xml option was deprecated in version 2.7 and will be removed in version 3.0. Use the --format option instead.', E_USER_DEPRECATED);
82 $input->setOption('format', 'xml');
85 $helper = new DescriptorHelper();
86 $helper->describe($output, $this->command, array(
87 'format' => $input->getOption('format'),
88 'raw_text' => $input->getOption('raw'),
91 $this->command = null;