Command.php
1 year ago
CompleteCommand.php
1 year ago
DumpCompletionCommand.php
2 years ago
HelpCommand.php
2 years ago
LazyCommand.php
1 year ago
ListCommand.php
2 years ago
LockableTrait.php
1 year ago
SignalableCommandInterface.php
2 years ago
ListCommand.php
74 lines
| 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 | namespace Matomo\Dependencies\Symfony\Component\Console\Command; |
| 12 | |
| 13 | use Matomo\Dependencies\Symfony\Component\Console\Completion\CompletionInput; |
| 14 | use Matomo\Dependencies\Symfony\Component\Console\Completion\CompletionSuggestions; |
| 15 | use Matomo\Dependencies\Symfony\Component\Console\Descriptor\ApplicationDescription; |
| 16 | use Matomo\Dependencies\Symfony\Component\Console\Helper\DescriptorHelper; |
| 17 | use Matomo\Dependencies\Symfony\Component\Console\Input\InputArgument; |
| 18 | use Matomo\Dependencies\Symfony\Component\Console\Input\InputInterface; |
| 19 | use Matomo\Dependencies\Symfony\Component\Console\Input\InputOption; |
| 20 | use Matomo\Dependencies\Symfony\Component\Console\Output\OutputInterface; |
| 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 | /** |
| 29 | * {@inheritdoc} |
| 30 | */ |
| 31 | protected function configure() |
| 32 | { |
| 33 | $this->setName('list')->setDefinition([new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'), new InputOption('short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments')])->setDescription('List commands')->setHelp(<<<'EOF' |
| 34 | The <info>%command.name%</info> command lists all commands: |
| 35 | |
| 36 | <info>%command.full_name%</info> |
| 37 | |
| 38 | You can also display the commands for a specific namespace: |
| 39 | |
| 40 | <info>%command.full_name% test</info> |
| 41 | |
| 42 | You can also output the information in other formats by using the <comment>--format</comment> option: |
| 43 | |
| 44 | <info>%command.full_name% --format=xml</info> |
| 45 | |
| 46 | It's also possible to get raw list of commands (useful for embedding command runner): |
| 47 | |
| 48 | <info>%command.full_name% --raw</info> |
| 49 | EOF |
| 50 | ); |
| 51 | } |
| 52 | /** |
| 53 | * {@inheritdoc} |
| 54 | */ |
| 55 | protected function execute(InputInterface $input, OutputInterface $output) |
| 56 | { |
| 57 | $helper = new DescriptorHelper(); |
| 58 | $helper->describe($output, $this->getApplication(), ['format' => $input->getOption('format'), 'raw_text' => $input->getOption('raw'), 'namespace' => $input->getArgument('namespace'), 'short' => $input->getOption('short')]); |
| 59 | return 0; |
| 60 | } |
| 61 | public function complete(CompletionInput $input, CompletionSuggestions $suggestions) : void |
| 62 | { |
| 63 | if ($input->mustSuggestArgumentValuesFor('namespace')) { |
| 64 | $descriptor = new ApplicationDescription($this->getApplication()); |
| 65 | $suggestions->suggestValues(array_keys($descriptor->getNamespaces())); |
| 66 | return; |
| 67 | } |
| 68 | if ($input->mustSuggestOptionValuesFor('format')) { |
| 69 | $helper = new DescriptorHelper(); |
| 70 | $suggestions->suggestValues($helper->getFormats()); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 |