PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / Command / HelpCommand.php

HelpCommand.php in Depicter — Popup & Slider Builder trunk, at vendor/symfony/console/Command/HelpCommand.php

102 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Completion\CompletionInput;
15 use Symfony\Component\Console\Completion\CompletionSuggestions;
16 use Symfony\Component\Console\Descriptor\ApplicationDescription;
17 use Symfony\Component\Console\Helper\DescriptorHelper;
18 use Symfony\Component\Console\Input\InputArgument;
19 use Symfony\Component\Console\Input\InputInterface;
20 use Symfony\Component\Console\Input\InputOption;
21 use Symfony\Component\Console\Output\OutputInterface;
22
23 /**
24 * HelpCommand displays the help for a given command.
25 *
26 * @author Fabien Potencier <fabien@symfony.com>
27 */
28 class HelpCommand extends Command
29 {
30 private $command;
31
32 /**
33 * {@inheritdoc}
34 */
35 protected function configure()
36 {
37 $this->ignoreValidationErrors();
38
39 $this
40 ->setName('help')
41 ->setDefinition([
42 new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
43 new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
44 new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
45 ])
46 ->setDescription('Display help for a command')
47 ->setHelp(<<<'EOF'
48 The <info>%command.name%</info> command displays help for a given command:
49
50 <info>%command.full_name% list</info>
51
52 You can also output the help in other formats by using the <comment>--format</comment> option:
53
54 <info>%command.full_name% --format=xml list</info>
55
56 To display the list of available commands, please use the <info>list</info> command.
57 EOF
58 )
59 ;
60 }
61
62 public function setCommand(Command $command)
63 {
64 $this->command = $command;
65 }
66
67 /**
68 * {@inheritdoc}
69 */
70 protected function execute(InputInterface $input, OutputInterface $output)
71 {
72 if (null === $this->command) {
73 $this->command = $this->getApplication()->find($input->getArgument('command_name'));
74 }
75
76 $helper = new DescriptorHelper();
77 $helper->describe($output, $this->command, [
78 'format' => $input->getOption('format'),
79 'raw_text' => $input->getOption('raw'),
80 ]);
81
82 $this->command = null;
83
84 return 0;
85 }
86
87 public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
88 {
89 if ($input->mustSuggestArgumentValuesFor('command_name')) {
90 $descriptor = new ApplicationDescription($this->getApplication());
91 $suggestions->suggestValues(array_keys($descriptor->getCommands()));
92
93 return;
94 }
95
96 if ($input->mustSuggestOptionValuesFor('format')) {
97 $helper = new DescriptorHelper();
98 $suggestions->suggestValues($helper->getFormats());
99 }
100 }
101 }
102