Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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
 
12
namespace Symfony\Component\Console\Command;
13
 
14
use Symfony\Component\Console\Descriptor\ApplicationDescription;
15
use Symfony\Component\Console\Helper\DescriptorHelper;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
 
21
/**
22
 * HelpCommand displays the help for a given command.
23
 *
24
 * @author Fabien Potencier <fabien@symfony.com>
25
 */
26
class HelpCommand extends Command
27
{
28
    private Command $command;
29
 
30
    protected function configure()
31
    {
32
        $this->ignoreValidationErrors();
33
 
34
        $this
35
            ->setName('help')
36
            ->setDefinition([
37
                new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help', function () {
38
                    return array_keys((new ApplicationDescription($this->getApplication()))->getCommands());
39
                }),
40
                new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', function () {
41
                    return (new DescriptorHelper())->getFormats();
42
                }),
43
                new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
44
            ])
45
            ->setDescription('Display help for a command')
46
            ->setHelp(<<<'EOF'
47
The <info>%command.name%</info> command displays help for a given command:
48
 
49
  <info>%command.full_name% list</info>
50
 
51
You can also output the help in other formats by using the <comment>--format</comment> option:
52
 
53
  <info>%command.full_name% --format=xml list</info>
54
 
55
To display the list of available commands, please use the <info>list</info> command.
56
EOF
57
            )
58
        ;
59
    }
60
 
61
    public function setCommand(Command $command)
62
    {
63
        $this->command = $command;
64
    }
65
 
66
    protected function execute(InputInterface $input, OutputInterface $output): int
67
    {
68
        $this->command ??= $this->getApplication()->find($input->getArgument('command_name'));
69
 
70
        $helper = new DescriptorHelper();
71
        $helper->describe($output, $this->command, [
72
            'format' => $input->getOption('format'),
73
            'raw_text' => $input->getOption('raw'),
74
        ]);
75
 
76
        unset($this->command);
77
 
78
        return 0;
79
    }
80
}