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
 * ListCommand displays the list of all available commands for the application.
23
 *
24
 * @author Fabien Potencier <fabien@symfony.com>
25
 */
26
class ListCommand extends Command
27
{
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('list')
32
            ->setDefinition([
33
                new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name', null, function () {
34
                    return array_keys((new ApplicationDescription($this->getApplication()))->getNamespaces());
35
                }),
36
                new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
37
                new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', function () {
38
                    return (new DescriptorHelper())->getFormats();
39
                }),
40
                new InputOption('short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments'),
41
            ])
42
            ->setDescription('List commands')
43
            ->setHelp(<<<'EOF'
44
The <info>%command.name%</info> command lists all commands:
45
 
46
  <info>%command.full_name%</info>
47
 
48
You can also display the commands for a specific namespace:
49
 
50
  <info>%command.full_name% test</info>
51
 
52
You can also output the information in other formats by using the <comment>--format</comment> option:
53
 
54
  <info>%command.full_name% --format=xml</info>
55
 
56
It's also possible to get raw list of commands (useful for embedding command runner):
57
 
58
  <info>%command.full_name% --raw</info>
59
EOF
60
            )
61
        ;
62
    }
63
 
64
    protected function execute(InputInterface $input, OutputInterface $output): int
65
    {
66
        $helper = new DescriptorHelper();
67
        $helper->describe($output, $this->getApplication(), [
68
            'format' => $input->getOption('format'),
69
            'raw_text' => $input->getOption('raw'),
70
            'namespace' => $input->getArgument('namespace'),
71
            'short' => $input->getOption('short'),
72
        ]);
73
 
74
        return 0;
75
    }
76
}