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@0
|
16 use Symfony\Component\Console\Input\InputOption;
|
Chris@0
|
17 use Symfony\Component\Console\Input\InputInterface;
|
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@0
|
38 ->setDefinition(array(
|
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@0
|
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 /**
|
Chris@0
|
60 * Sets the command.
|
Chris@0
|
61 *
|
Chris@0
|
62 * @param Command $command The command to set
|
Chris@0
|
63 */
|
Chris@0
|
64 public function setCommand(Command $command)
|
Chris@0
|
65 {
|
Chris@0
|
66 $this->command = $command;
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 /**
|
Chris@0
|
70 * {@inheritdoc}
|
Chris@0
|
71 */
|
Chris@0
|
72 protected function execute(InputInterface $input, OutputInterface $output)
|
Chris@0
|
73 {
|
Chris@0
|
74 if (null === $this->command) {
|
Chris@0
|
75 $this->command = $this->getApplication()->find($input->getArgument('command_name'));
|
Chris@0
|
76 }
|
Chris@0
|
77
|
Chris@0
|
78 $helper = new DescriptorHelper();
|
Chris@0
|
79 $helper->describe($output, $this->command, array(
|
Chris@0
|
80 'format' => $input->getOption('format'),
|
Chris@0
|
81 'raw_text' => $input->getOption('raw'),
|
Chris@0
|
82 ));
|
Chris@0
|
83
|
Chris@0
|
84 $this->command = null;
|
Chris@0
|
85 }
|
Chris@0
|
86 }
|