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\Input\InputArgument;
15 use Symfony\Component\Console\Input\InputOption;
16 use Symfony\Component\Console\Input\InputInterface;
17 use Symfony\Component\Console\Output\OutputInterface;
18 use Symfony\Component\Console\Output\Output;
19 use Symfony\Component\Console\Command\Command;
22 * HelpCommand displays the help for a given command.
24 * @author Fabien Potencier <fabien@symfony.com>
26 class HelpCommand extends Command
33 protected function configure()
35 $this->ignoreValidationErrors();
39 ->setDefinition(array(
40 new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
41 new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
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 as XML by using the <comment>--xml</comment> option:
51 <info>php %command.full_name% --xml list</info>
60 * @param Command $command The command to set
62 public function setCommand(Command $command)
64 $this->command = $command;
70 protected function execute(InputInterface $input, OutputInterface $output)
72 if (null === $this->command) {
73 $this->command = $this->getApplication()->get($input->getArgument('command_name'));
76 if ($input->getOption('xml')) {
77 $output->writeln($this->command->asXml(), OutputInterface::OUTPUT_RAW);
79 $output->writeln($this->command->asText());
82 $this->command = null;