Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df38318

Browse files
committed
feature #21075 [Console] Show hidden commands in json & xml descriptors (ogizanagi)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Console] Show hidden commands in json & xml descriptors | Q | A | ------------- | --- | Branch? | master | Bug fix? | no (may be considered, but as hidden commands did not exist before 3.2, looks more like a behavior change, hence a feature) | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20866 (comment) | License | MIT | Doc PR | N/A Commits ------- b6cf240 [Console] Show hidden commands in json & xml descriptors
2 parents ed5eb6d + b6cf240 commit df38318

12 files changed

+141
-14
lines changed

src/Symfony/Component/Console/Descriptor/ApplicationDescription.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,23 @@ class ApplicationDescription
4949
*/
5050
private $aliases;
5151

52+
/**
53+
* @var bool
54+
*/
55+
private $showHidden;
56+
5257
/**
5358
* Constructor.
5459
*
5560
* @param Application $application
5661
* @param string|null $namespace
62+
* @param bool $showHidden
5763
*/
58-
public function __construct(Application $application, $namespace = null)
64+
public function __construct(Application $application, $namespace = null, $showHidden = false)
5965
{
6066
$this->application = $application;
6167
$this->namespace = $namespace;
68+
$this->showHidden = $showHidden;
6269
}
6370

6471
/**
@@ -112,7 +119,7 @@ private function inspectApplication()
112119

113120
/** @var Command $command */
114121
foreach ($commands as $name => $command) {
115-
if (!$command->getName() || $command->isHidden()) {
122+
if (!$command->getName() || (!$this->showHidden && $command->isHidden())) {
116123
continue;
117124
}
118125

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function describeCommand(Command $command, array $options = array())
6464
protected function describeApplication(Application $application, array $options = array())
6565
{
6666
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
67-
$description = new ApplicationDescription($application, $describedNamespace);
67+
$description = new ApplicationDescription($application, $describedNamespace, true);
6868
$commands = array();
6969

7070
foreach ($description->getCommands() as $command) {
@@ -173,6 +173,7 @@ private function getCommandData(Command $command)
173173
'description' => $command->getDescription(),
174174
'help' => $command->getProcessedHelp(),
175175
'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
176+
'hidden' => $command->isHidden(),
176177
);
177178
}
178179
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function getCommandDocument(Command $command)
6464

6565
$commandXML->setAttribute('id', $command->getName());
6666
$commandXML->setAttribute('name', $command->getName());
67+
$commandXML->setAttribute('hidden', $command->isHidden() ? 1 : 0);
6768

6869
$commandXML->appendChild($usagesXML = $dom->createElement('usages'));
6970

@@ -103,7 +104,7 @@ public function getApplicationDocument(Application $application, $namespace = nu
103104

104105
$rootXml->appendChild($commandsXML = $dom->createElement('commands'));
105106

106-
$description = new ApplicationDescription($application, $namespace);
107+
$description = new ApplicationDescription($application, $namespace, true);
107108

108109
if ($namespace) {
109110
$commandsXML->setAttribute('namespace', $namespace);

src/Symfony/Component/Console/Tests/Command/ListCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testExecuteListsCommandsWithXmlOption()
3030
$application = new Application();
3131
$commandTester = new CommandTester($command = $application->get('list'));
3232
$commandTester->execute(array('command' => $command->getName(), '--format' => 'xml'));
33-
$this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
33+
$this->assertRegExp('/<command id="list" name="list" hidden="0">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
3434
}
3535

3636
public function testExecuteListsCommandsWithRawOption()

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"commands": [
33
{
44
"name": "help",
5+
"hidden": false,
56
"usage": [
67
"help [--format FORMAT] [--raw] [--] [<command_name>]"
78
],
@@ -104,6 +105,7 @@
104105
},
105106
{
106107
"name": "list",
108+
"hidden": false,
107109
"usage": [
108110
"list [--raw] [--format FORMAT] [--] [<namespace>]"
109111
],

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<symfony>
33
<commands>
4-
<command id="help" name="help">
4+
<command id="help" name="help" hidden="0">
55
<usages>
66
<usage>help [--format FORMAT] [--raw] [--] [&lt;command_name&gt;]</usage>
77
</usages>
@@ -56,7 +56,7 @@
5656
</option>
5757
</options>
5858
</command>
59-
<command id="list" name="list">
59+
<command id="list" name="list" hidden="0">
6060
<usages>
6161
<usage>list [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]</usage>
6262
</usages>

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

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"commands": [
77
{
88
"name": "help",
9+
"hidden": false,
910
"usage": [
1011
"help [--format FORMAT] [--raw] [--] [<command_name>]"
1112
],
@@ -108,6 +109,7 @@
108109
},
109110
{
110111
"name": "list",
112+
"hidden": false,
111113
"usage": [
112114
"list [--raw] [--format FORMAT] [--] [<namespace>]"
113115
],
@@ -147,6 +149,7 @@
147149
},
148150
{
149151
"name": "descriptor:command1",
152+
"hidden": false,
150153
"usage": [
151154
"descriptor:command1",
152155
"alias1",
@@ -225,6 +228,7 @@
225228
},
226229
{
227230
"name": "descriptor:command2",
231+
"hidden": false,
228232
"usage": [
229233
"descriptor:command2 [-o|--option_name] [--] <argument_name>",
230234
"descriptor:command2 -o|--option_name <argument_name>",
@@ -317,6 +321,83 @@
317321
}
318322
}
319323
}
324+
},
325+
{
326+
"name": "descriptor:command3",
327+
"hidden": true,
328+
"usage": [
329+
"descriptor:command3"
330+
],
331+
"description": "command 3 description",
332+
"help": "command 3 help",
333+
"definition": {
334+
"arguments": {},
335+
"options": {
336+
"help": {
337+
"name": "--help",
338+
"shortcut": "-h",
339+
"accept_value": false,
340+
"is_value_required": false,
341+
"is_multiple": false,
342+
"description": "Display this help message",
343+
"default": false
344+
},
345+
"quiet": {
346+
"name": "--quiet",
347+
"shortcut": "-q",
348+
"accept_value": false,
349+
"is_value_required": false,
350+
"is_multiple": false,
351+
"description": "Do not output any message",
352+
"default": false
353+
},
354+
"verbose": {
355+
"name": "--verbose",
356+
"shortcut": "-v|-vv|-vvv",
357+
"accept_value": false,
358+
"is_value_required": false,
359+
"is_multiple": false,
360+
"description": "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug",
361+
"default": false
362+
},
363+
"version": {
364+
"name": "--version",
365+
"shortcut": "-V",
366+
"accept_value": false,
367+
"is_value_required": false,
368+
"is_multiple": false,
369+
"description": "Display this application version",
370+
"default": false
371+
},
372+
"ansi": {
373+
"name": "--ansi",
374+
"shortcut": "",
375+
"accept_value": false,
376+
"is_value_required": false,
377+
"is_multiple": false,
378+
"description": "Force ANSI output",
379+
"default": false
380+
},
381+
"no-ansi": {
382+
"name": "--no-ansi",
383+
"shortcut": "",
384+
"accept_value": false,
385+
"is_value_required": false,
386+
"is_multiple": false,
387+
"description": "Disable ANSI output",
388+
"default": false
389+
},
390+
"no-interaction": {
391+
"name": "--no-interaction",
392+
"shortcut": "-n",
393+
"accept_value": false,
394+
"is_value_required": false,
395+
"is_multiple": false,
396+
"description": "Do not ask any interactive question",
397+
"default": false
398+
}
399+
}
400+
}
320401
}
321402
],
322403
"namespaces": [
@@ -333,7 +414,8 @@
333414
"id": "descriptor",
334415
"commands": [
335416
"descriptor:command1",
336-
"descriptor:command2"
417+
"descriptor:command2",
418+
"descriptor:command3"
337419
]
338420
}
339421
]

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<symfony name="My Symfony application" version="v1.0">
33
<commands>
4-
<command id="help" name="help">
4+
<command id="help" name="help" hidden="0">
55
<usages>
66
<usage>help [--format FORMAT] [--raw] [--] [&lt;command_name&gt;]</usage>
77
</usages>
@@ -56,7 +56,7 @@
5656
</option>
5757
</options>
5858
</command>
59-
<command id="list" name="list">
59+
<command id="list" name="list" hidden="0">
6060
<usages>
6161
<usage>list [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]</usage>
6262
</usages>
@@ -94,7 +94,7 @@
9494
</option>
9595
</options>
9696
</command>
97-
<command id="descriptor:command1" name="descriptor:command1">
97+
<command id="descriptor:command1" name="descriptor:command1" hidden="0">
9898
<usages>
9999
<usage>descriptor:command1</usage>
100100
<usage>alias1</usage>
@@ -127,7 +127,7 @@
127127
</option>
128128
</options>
129129
</command>
130-
<command id="descriptor:command2" name="descriptor:command2">
130+
<command id="descriptor:command2" name="descriptor:command2" hidden="0">
131131
<usages>
132132
<usage>descriptor:command2 [-o|--option_name] [--] &lt;argument_name&gt;</usage>
133133
<usage>descriptor:command2 -o|--option_name &lt;argument_name&gt;</usage>
@@ -168,6 +168,37 @@
168168
</option>
169169
</options>
170170
</command>
171+
<command id="descriptor:command3" name="descriptor:command3" hidden="1">
172+
<usages>
173+
<usage>descriptor:command3</usage>
174+
</usages>
175+
<description>command 3 description</description>
176+
<help>command 3 help</help>
177+
<arguments/>
178+
<options>
179+
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
180+
<description>Display this help message</description>
181+
</option>
182+
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
183+
<description>Do not output any message</description>
184+
</option>
185+
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
186+
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
187+
</option>
188+
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
189+
<description>Display this application version</description>
190+
</option>
191+
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
192+
<description>Force ANSI output</description>
193+
</option>
194+
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
195+
<description>Disable ANSI output</description>
196+
</option>
197+
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
198+
<description>Do not ask any interactive question</description>
199+
</option>
200+
</options>
201+
</command>
171202
</commands>
172203
<namespaces>
173204
<namespace id="_global">
@@ -179,6 +210,7 @@
179210
<namespace id="descriptor">
180211
<command>descriptor:command1</command>
181212
<command>descriptor:command2</command>
213+
<command>descriptor:command3</command>
182214
</namespace>
183215
</namespaces>
184216
</symfony>

src/Symfony/Component/Console/Tests/Fixtures/command_1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "descriptor:command1",
3+
"hidden": false,
34
"usage": [
45
"descriptor:command1",
56
"alias1",

src/Symfony/Component/Console/Tests/Fixtures/command_1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<command id="descriptor:command1" name="descriptor:command1">
2+
<command id="descriptor:command1" name="descriptor:command1" hidden="0">
33
<usages>
44
<usage>descriptor:command1</usage>
55
<usage>alias1</usage>

src/Symfony/Component/Console/Tests/Fixtures/command_2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "descriptor:command2",
3+
"hidden": false,
34
"usage": [
45
"descriptor:command2 [-o|--option_name] [--] <argument_name>",
56
"descriptor:command2 -o|--option_name <argument_name>",

src/Symfony/Component/Console/Tests/Fixtures/command_2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<command id="descriptor:command2" name="descriptor:command2">
2+
<command id="descriptor:command2" name="descriptor:command2" hidden="0">
33
<usages>
44
<usage>descriptor:command2 [-o|--option_name] [--] &lt;argument_name&gt;</usage>
55
<usage>descriptor:command2 -o|--option_name &lt;argument_name&gt;</usage>

0 commit comments

Comments
 (0)