source: pro-violet-viettel/sourcecode/application/libraries/Doctrine/Symfony/Component/Console/Command/HelpCommand.php @ 345

Last change on this file since 345 was 345, checked in by quyenla, 11 years ago

collaborator page

File size: 2.1 KB
Line 
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Console\Command;
13
14use Symfony\Component\Console\Input\InputArgument;
15use Symfony\Component\Console\Input\InputOption;
16use Symfony\Component\Console\Input\InputInterface;
17use Symfony\Component\Console\Output\OutputInterface;
18use Symfony\Component\Console\Output\Output;
19use Symfony\Component\Console\Command\Command;
20
21/**
22 * HelpCommand displays the help for a given command.
23 *
24 * @author Fabien Potencier <fabien@symfony.com>
25 */
26class HelpCommand extends Command
27{
28    private $command;
29
30    /**
31     * {@inheritdoc}
32     */
33    protected function configure()
34    {
35        $this->ignoreValidationErrors = true;
36
37        $this
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            ))
42            ->setName('help')
43            ->setDescription('Displays help for a command')
44            ->setHelp(<<<EOF
45The <info>help</info> command displays help for a given command:
46
47  <info>./symfony help list</info>
48
49You can also output the help as XML by using the <comment>--xml</comment> option:
50
51  <info>./symfony help --xml list</info>
52EOF
53            );
54    }
55
56    /**
57     * Sets the command
58     *
59     * @param Command $command The command to set
60     */
61    public function setCommand(Command $command)
62    {
63        $this->command = $command;
64    }
65
66    /**
67     * {@inheritdoc}
68     */
69    protected function execute(InputInterface $input, OutputInterface $output)
70    {
71        if (null === $this->command) {
72            $this->command = $this->getApplication()->get($input->getArgument('command_name'));
73        }
74
75        if ($input->getOption('xml')) {
76            $output->writeln($this->command->asXml(), OutputInterface::OUTPUT_RAW);
77        } else {
78            $output->writeln($this->command->asText());
79        }
80    }
81}
Note: See TracBrowser for help on using the repository browser.