Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3674966

Browse filesBrowse files
[Console] add option --short to the list command
1 parent 4cb45fe commit 3674966
Copy full SHA for 3674966

16 files changed

+126
-35
lines changed

‎src/Symfony/Component/Console/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* Add `InputOption::VALUE_NEGATABLE` flag to handle `--foo`/`--no-foo` options
99
* Add the `Command::$defaultDescription` static property and the `description` attribute
1010
on the `console.command` tag to allow the `list` command to instantiate commands lazily
11+
* Add option `--short` to the `list` command
1112

1213
5.2.0
1314
-----

‎src/Symfony/Component/Console/Command/ListCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/ListCommand.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ protected function configure()
3535
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
3636
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
3737
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
38+
new InputOption('short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments'),
3839
])
3940
->setDescription('Lists commands')
4041
->setHelp(<<<'EOF'
@@ -68,6 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6869
'format' => $input->getOption('format'),
6970
'raw_text' => $input->getOption('raw'),
7071
'namespace' => $input->getArgument('namespace'),
72+
'short' => $input->getOption('short'),
7173
]);
7274

7375
return 0;

‎src/Symfony/Component/Console/Descriptor/JsonDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Descriptor/JsonDescriptor.php
+22-10Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function describeInputDefinition(InputDefinition $definition, array $o
5858
*/
5959
protected function describeCommand(Command $command, array $options = [])
6060
{
61-
$this->writeData($this->getCommandData($command), $options);
61+
$this->writeData($this->getCommandData($command, $options['short'] ?? false), $options);
6262
}
6363

6464
/**
@@ -71,7 +71,7 @@ protected function describeApplication(Application $application, array $options
7171
$commands = [];
7272

7373
foreach ($description->getCommands() as $command) {
74-
$commands[] = $this->getCommandData($command);
74+
$commands[] = $this->getCommandData($command, $options['short'] ?? false);
7575
}
7676

7777
$data = [];
@@ -153,17 +153,29 @@ private function getInputDefinitionData(InputDefinition $definition): array
153153
return ['arguments' => $inputArguments, 'options' => $inputOptions];
154154
}
155155

156-
private function getCommandData(Command $command): array
156+
private function getCommandData(Command $command, bool $short = false): array
157157
{
158-
$command->mergeApplicationDefinition(false);
159-
160-
return [
158+
$data = [
161159
'name' => $command->getName(),
162-
'usage' => array_merge([$command->getSynopsis()], $command->getUsages(), $command->getAliases()),
163160
'description' => $command->getDescription(),
164-
'help' => $command->getProcessedHelp(),
165-
'definition' => $this->getInputDefinitionData($command->getDefinition()),
166-
'hidden' => $command->isHidden(),
167161
];
162+
163+
if ($short) {
164+
$data += [
165+
'usage' => $command->getAliases(),
166+
];
167+
} else {
168+
$command->mergeApplicationDefinition(false);
169+
170+
$data += [
171+
'usage' => array_merge([$command->getSynopsis()], $command->getUsages(), $command->getAliases()),
172+
'help' => $command->getProcessedHelp(),
173+
'definition' => $this->getInputDefinitionData($command->getDefinition()),
174+
];
175+
}
176+
177+
$data['hidden'] = $command->isHidden();
178+
179+
return $data;
168180
}
169181
}

‎src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ protected function describeInputDefinition(InputDefinition $definition, array $o
122122
*/
123123
protected function describeCommand(Command $command, array $options = [])
124124
{
125+
if ($options['short'] ?? false) {
126+
$this->write(
127+
'`'.$command->getName()."`\n"
128+
.str_repeat('-', Helper::strlen($command->getName()) + 2)."\n\n"
129+
.($command->getDescription() ? $command->getDescription()."\n\n" : '')
130+
.'### Usage'."\n\n"
131+
.array_reduce($command->getAliases(), function ($carry, $usage) {
132+
return $carry.'* `'.$usage.'`'."\n";
133+
})
134+
);
135+
136+
return;
137+
}
138+
125139
$command->mergeApplicationDefinition(false);
126140

127141
$this->write(
@@ -171,7 +185,7 @@ protected function describeApplication(Application $application, array $options
171185

172186
foreach ($description->getCommands() as $command) {
173187
$this->write("\n\n");
174-
if (null !== $describeCommand = $this->describeCommand($command)) {
188+
if (null !== $describeCommand = $this->describeCommand($command, $options)) {
175189
$this->write($describeCommand);
176190
}
177191
}

‎src/Symfony/Component/Console/Descriptor/XmlDescriptor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Descriptor/XmlDescriptor.php
+21-15Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,42 @@ public function getInputDefinitionDocument(InputDefinition $definition): \DOMDoc
4444
return $dom;
4545
}
4646

47-
public function getCommandDocument(Command $command): \DOMDocument
47+
public function getCommandDocument(Command $command, bool $short = false): \DOMDocument
4848
{
4949
$dom = new \DOMDocument('1.0', 'UTF-8');
5050
$dom->appendChild($commandXML = $dom->createElement('command'));
5151

52-
$command->mergeApplicationDefinition(false);
53-
5452
$commandXML->setAttribute('id', $command->getName());
5553
$commandXML->setAttribute('name', $command->getName());
5654
$commandXML->setAttribute('hidden', $command->isHidden() ? 1 : 0);
5755

5856
$commandXML->appendChild($usagesXML = $dom->createElement('usages'));
5957

60-
foreach (array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()) as $usage) {
61-
$usagesXML->appendChild($dom->createElement('usage', $usage));
62-
}
63-
6458
$commandXML->appendChild($descriptionXML = $dom->createElement('description'));
6559
$descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription())));
6660

67-
$commandXML->appendChild($helpXML = $dom->createElement('help'));
68-
$helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));
61+
if ($short) {
62+
foreach ($command->getAliases() as $usage) {
63+
$usagesXML->appendChild($dom->createElement('usage', $usage));
64+
}
65+
} else {
66+
$command->mergeApplicationDefinition(false);
6967

70-
$definitionXML = $this->getInputDefinitionDocument($command->getDefinition());
71-
$this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));
68+
foreach (array_merge([$command->getSynopsis()], $command->getAliases(), $command->getUsages()) as $usage) {
69+
$usagesXML->appendChild($dom->createElement('usage', $usage));
70+
}
71+
72+
$commandXML->appendChild($helpXML = $dom->createElement('help'));
73+
$helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));
74+
75+
$definitionXML = $this->getInputDefinitionDocument($command->getDefinition());
76+
$this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));
77+
}
7278

7379
return $dom;
7480
}
7581

76-
public function getApplicationDocument(Application $application, string $namespace = null): \DOMDocument
82+
public function getApplicationDocument(Application $application, string $namespace = null, bool $short = true): \DOMDocument
7783
{
7884
$dom = new \DOMDocument('1.0', 'UTF-8');
7985
$dom->appendChild($rootXml = $dom->createElement('symfony'));
@@ -94,7 +100,7 @@ public function getApplicationDocument(Application $application, string $namespa
94100
}
95101

96102
foreach ($description->getCommands() as $command) {
97-
$this->appendDocument($commandsXML, $this->getCommandDocument($command));
103+
$this->appendDocument($commandsXML, $this->getCommandDocument($command, $short));
98104
}
99105

100106
if (!$namespace) {
@@ -143,15 +149,15 @@ protected function describeInputDefinition(InputDefinition $definition, array $o
143149
*/
144150
protected function describeCommand(Command $command, array $options = [])
145151
{
146-
$this->writeDocument($this->getCommandDocument($command));
152+
$this->writeDocument($this->getCommandDocument($command, $options['short'] ?? false));
147153
}
148154

149155
/**
150156
* {@inheritdoc}
151157
*/
152158
protected function describeApplication(Application $application, array $options = [])
153159
{
154-
$this->writeDocument($this->getApplicationDocument($application, $options['namespace'] ?? null));
160+
$this->writeDocument($this->getApplicationDocument($application, $options['namespace'] ?? null, $options['short'] ?? false));
155161
}
156162

157163
/**

‎src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testExecuteForApplicationCommandWithXmlOption()
6565
$application = new Application();
6666
$commandTester = new CommandTester($application->get('help'));
6767
$commandTester->execute(['command_name' => 'list', '--format' => 'xml']);
68-
$this->assertStringContainsString('list [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
68+
$this->assertStringContainsString('list [--raw] [--format FORMAT] [--short] [--] [&lt;namespace&gt;]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
6969
$this->assertStringContainsString('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed');
7070
}
7171
}

‎src/Symfony/Component/Console/Tests/Fixtures/application_1.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_1.json
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"name": "list",
108108
"hidden": false,
109109
"usage": [
110-
"list [--raw] [--format FORMAT] [--] [<namespace>]"
110+
"list [--raw] [--format FORMAT] [--short] [--] [<namespace>]"
111111
],
112112
"description": "Lists commands",
113113
"help": "The <info>list<\/info> command lists all commands:\n\n <info>app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n <info>app\/console list --raw<\/info>",
@@ -202,6 +202,15 @@
202202
"is_multiple": false,
203203
"description": "Do not ask any interactive question",
204204
"default": false
205+
},
206+
"short": {
207+
"name": "--short",
208+
"shortcut": "",
209+
"accept_value": false,
210+
"is_value_required": false,
211+
"is_multiple": false,
212+
"description": "To skip describing commands' arguments",
213+
"default": false
205214
}
206215
}
207216
}

‎src/Symfony/Component/Console/Tests/Fixtures/application_1.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_1.md
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Lists commands
122122

123123
### Usage
124124

125-
* `list [--raw] [--format FORMAT] [--] [<namespace>]`
125+
* `list [--raw] [--format FORMAT] [--short] [--] [<namespace>]`
126126

127127
The list command lists all commands:
128128

@@ -172,6 +172,16 @@ The output format (txt, xml, json, or md)
172172
* Is negatable: no
173173
* Default: `'txt'`
174174

175+
#### `--short`
176+
177+
To skip describing commands' arguments
178+
179+
* Accept value: no
180+
* Is value required: no
181+
* Is multiple: no
182+
* Is negatable: no
183+
* Default: `false`
184+
175185
#### `--help|-h`
176186

177187
Display help for the given command. When no command is given display help for the list command

‎src/Symfony/Component/Console/Tests/Fixtures/application_1.xml

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_1.xml
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</command>
5959
<command id="list" name="list" hidden="0">
6060
<usages>
61-
<usage>list [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]</usage>
61+
<usage>list [--raw] [--format FORMAT] [--short] [--] [&lt;namespace&gt;]</usage>
6262
</usages>
6363
<description>Lists commands</description>
6464
<help>The &lt;info&gt;list&lt;/info&gt; command lists all commands:
@@ -92,6 +92,9 @@
9292
<default>txt</default>
9393
</defaults>
9494
</option>
95+
<option name="--short" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
96+
<description>To skip describing commands' arguments</description>
97+
</option>
9598
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
9699
<description>Display help for the given command. When no command is given display help for the &lt;info&gt;list&lt;/info&gt; command</description>
97100
</option>

‎src/Symfony/Component/Console/Tests/Fixtures/application_2.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_2.json
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"name": "list",
112112
"hidden": false,
113113
"usage": [
114-
"list [--raw] [--format FORMAT] [--] [<namespace>]"
114+
"list [--raw] [--format FORMAT] [--short] [--] [<namespace>]"
115115
],
116116
"description": "Lists commands",
117117
"help": "The <info>list<\/info> command lists all commands:\n\n <info>app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n <info>app\/console list --raw<\/info>",
@@ -206,6 +206,15 @@
206206
"is_multiple": false,
207207
"description": "Do not ask any interactive question",
208208
"default": false
209+
},
210+
"short": {
211+
"name": "--short",
212+
"shortcut": "",
213+
"accept_value": false,
214+
"is_value_required": false,
215+
"is_multiple": false,
216+
"description": "To skip describing commands' arguments",
217+
"default": false
209218
}
210219
}
211220
}

‎src/Symfony/Component/Console/Tests/Fixtures/application_2.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_2.md
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Lists commands
135135

136136
### Usage
137137

138-
* `list [--raw] [--format FORMAT] [--] [<namespace>]`
138+
* `list [--raw] [--format FORMAT] [--short] [--] [<namespace>]`
139139

140140
The list command lists all commands:
141141

@@ -185,6 +185,16 @@ The output format (txt, xml, json, or md)
185185
* Is negatable: no
186186
* Default: `'txt'`
187187

188+
#### `--short`
189+
190+
To skip describing commands' arguments
191+
192+
* Accept value: no
193+
* Is value required: no
194+
* Is multiple: no
195+
* Is negatable: no
196+
* Default: `false`
197+
188198
#### `--help|-h`
189199

190200
Display help for the given command. When no command is given display help for the list command

‎src/Symfony/Component/Console/Tests/Fixtures/application_2.xml

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_2.xml
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</command>
5959
<command id="list" name="list" hidden="0">
6060
<usages>
61-
<usage>list [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]</usage>
61+
<usage>list [--raw] [--format FORMAT] [--short] [--] [&lt;namespace&gt;]</usage>
6262
</usages>
6363
<description>Lists commands</description>
6464
<help>The &lt;info&gt;list&lt;/info&gt; command lists all commands:
@@ -92,6 +92,9 @@
9292
<default>txt</default>
9393
</defaults>
9494
</option>
95+
<option name="--short" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
96+
<description>To skip describing commands' arguments</description>
97+
</option>
9598
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
9699
<description>Display help for the given command. When no command is given display help for the &lt;info&gt;list&lt;/info&gt; command</description>
97100
</option>

‎src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Lists commands
126126

127127
### Usage
128128

129-
* `list [--raw] [--format FORMAT] [--] [<namespace>]`
129+
* `list [--raw] [--format FORMAT] [--short] [--] [<namespace>]`
130130

131131
The list command lists all commands:
132132

@@ -176,6 +176,16 @@ The output format (txt, xml, json, or md)
176176
* Is negatable: no
177177
* Default: `'txt'`
178178

179+
#### `--short`
180+
181+
To skip describing commands' arguments
182+
183+
* Accept value: no
184+
* Is value required: no
185+
* Is multiple: no
186+
* Is negatable: no
187+
* Default: `false`
188+
179189
#### `--help|-h`
180190

181191
Display help for the given command. When no command is given display help for the list command

‎src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
The "--foo" option does not exist.
44

55

6-
list [--raw] [--format FORMAT] [--] [<namespace>]
6+
list [--raw] [--format FORMAT] [--short] [--] [<namespace>]
77

‎src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Arguments:
1010
Options:
1111
--raw To output raw command list
1212
--format=FORMAT The output format (txt, xml, json, or md) [default: "txt"]
13+
--short To skip describing commands' arguments
1314
-h, --help Display help for the given command. When no command is given display help for the list command
1415
-q, --quiet Do not output any message
1516
-V, --version Display this application version

‎src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Arguments:
1010
Options:
1111
--raw To output raw command list
1212
--format=FORMAT The output format (txt, xml, json, or md) [default: "txt"]
13+
--short To skip describing commands' arguments
1314
-h, --help Display help for the given command. When no command is given display help for the list command
1415
-q, --quiet Do not output any message
1516
-V, --version Display this application version

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.