Skip to content

[Console] Show hidden commands in json & xml descriptors #21075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,23 @@ class ApplicationDescription
*/
private $aliases;

/**
* @var bool
*/
private $showHidden;

/**
* Constructor.
*
* @param Application $application
* @param string|null $namespace
* @param bool $showHidden
*/
public function __construct(Application $application, $namespace = null)
public function __construct(Application $application, $namespace = null, $showHidden = false)
Copy link
Contributor

@ro0NL ro0NL Dec 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is good for sure 👍 same for updated outputs.

{
$this->application = $application;
$this->namespace = $namespace;
$this->showHidden = $showHidden;
}

/**
Expand Down Expand Up @@ -112,7 +119,7 @@ private function inspectApplication()

/** @var Command $command */
foreach ($commands as $name => $command) {
if (!$command->getName() || $command->isHidden()) {
if (!$command->getName() || (!$this->showHidden && $command->isHidden())) {
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Console/Descriptor/JsonDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function describeCommand(Command $command, array $options = array())
protected function describeApplication(Application $application, array $options = array())
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
Copy link
Contributor

@ro0NL ro0NL Dec 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion of getApplicationDescription was to move (global) option management to a single place. Keeping this doesnt solve that, gaining only 1 option * 4 descriptors.

Imo. we should rely on some $description->getNamespace() as of below, otherwise maybe revert.

$description = new ApplicationDescription($application, $describedNamespace);
$description = new ApplicationDescription($application, $describedNamespace, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo. the descriptor option was nice :) anyway it's internal code.. we're good 👍

$commands = array();

foreach ($description->getCommands() as $command) {
Expand Down Expand Up @@ -173,6 +173,7 @@ private function getCommandData(Command $command)
'description' => $command->getDescription(),
'help' => $command->getProcessedHelp(),
'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
'hidden' => $command->isHidden(),
);
}
}
3 changes: 2 additions & 1 deletion src/Symfony/Component/Console/Descriptor/XmlDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function getCommandDocument(Command $command)

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

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

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

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

$description = new ApplicationDescription($application, $namespace);
$description = new ApplicationDescription($application, $namespace, true);

if ($namespace) {
$commandsXML->setAttribute('namespace', $namespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testExecuteListsCommandsWithXmlOption()
$application = new Application();
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(array('command' => $command->getName(), '--format' => 'xml'));
$this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
$this->assertRegExp('/<command id="list" name="list" hidden="0">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
}

public function testExecuteListsCommandsWithRawOption()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"commands": [
{
"name": "help",
"hidden": false,
"usage": [
"help [--format FORMAT] [--raw] [--] [<command_name>]"
],
Expand Down Expand Up @@ -104,6 +105,7 @@
},
{
"name": "list",
"hidden": false,
"usage": [
"list [--raw] [--format FORMAT] [--] [<namespace>]"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<symfony>
<commands>
<command id="help" name="help">
<command id="help" name="help" hidden="0">
<usages>
<usage>help [--format FORMAT] [--raw] [--] [&lt;command_name&gt;]</usage>
</usages>
Expand Down Expand Up @@ -56,7 +56,7 @@
</option>
</options>
</command>
<command id="list" name="list">
<command id="list" name="list" hidden="0">
<usages>
<usage>list [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]</usage>
</usages>
Expand Down
84 changes: 83 additions & 1 deletion src/Symfony/Component/Console/Tests/Fixtures/application_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"commands": [
{
"name": "help",
"hidden": false,
"usage": [
"help [--format FORMAT] [--raw] [--] [<command_name>]"
],
Expand Down Expand Up @@ -108,6 +109,7 @@
},
{
"name": "list",
"hidden": false,
"usage": [
"list [--raw] [--format FORMAT] [--] [<namespace>]"
],
Expand Down Expand Up @@ -147,6 +149,7 @@
},
{
"name": "descriptor:command1",
"hidden": false,
"usage": [
"descriptor:command1",
"alias1",
Expand Down Expand Up @@ -225,6 +228,7 @@
},
{
"name": "descriptor:command2",
"hidden": false,
"usage": [
"descriptor:command2 [-o|--option_name] [--] <argument_name>",
"descriptor:command2 -o|--option_name <argument_name>",
Expand Down Expand Up @@ -317,6 +321,83 @@
}
}
}
},
{
"name": "descriptor:command3",
"hidden": true,
"usage": [
"descriptor:command3"
],
"description": "command 3 description",
"help": "command 3 help",
"definition": {
"arguments": {},
"options": {
"help": {
"name": "--help",
"shortcut": "-h",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Display this help message",
"default": false
},
"quiet": {
"name": "--quiet",
"shortcut": "-q",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not output any message",
"default": false
},
"verbose": {
"name": "--verbose",
"shortcut": "-v|-vv|-vvv",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug",
"default": false
},
"version": {
"name": "--version",
"shortcut": "-V",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Display this application version",
"default": false
},
"ansi": {
"name": "--ansi",
"shortcut": "",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Force ANSI output",
"default": false
},
"no-ansi": {
"name": "--no-ansi",
"shortcut": "",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Disable ANSI output",
"default": false
},
"no-interaction": {
"name": "--no-interaction",
"shortcut": "-n",
"accept_value": false,
"is_value_required": false,
"is_multiple": false,
"description": "Do not ask any interactive question",
"default": false
}
}
}
}
],
"namespaces": [
Expand All @@ -333,7 +414,8 @@
"id": "descriptor",
"commands": [
"descriptor:command1",
"descriptor:command2"
"descriptor:command2",
"descriptor:command3"
]
}
]
Expand Down
40 changes: 36 additions & 4 deletions src/Symfony/Component/Console/Tests/Fixtures/application_2.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<symfony name="My Symfony application" version="v1.0">
<commands>
<command id="help" name="help">
<command id="help" name="help" hidden="0">
<usages>
<usage>help [--format FORMAT] [--raw] [--] [&lt;command_name&gt;]</usage>
</usages>
Expand Down Expand Up @@ -56,7 +56,7 @@
</option>
</options>
</command>
<command id="list" name="list">
<command id="list" name="list" hidden="0">
<usages>
<usage>list [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]</usage>
</usages>
Expand Down Expand Up @@ -94,7 +94,7 @@
</option>
</options>
</command>
<command id="descriptor:command1" name="descriptor:command1">
<command id="descriptor:command1" name="descriptor:command1" hidden="0">
<usages>
<usage>descriptor:command1</usage>
<usage>alias1</usage>
Expand Down Expand Up @@ -127,7 +127,7 @@
</option>
</options>
</command>
<command id="descriptor:command2" name="descriptor:command2">
<command id="descriptor:command2" name="descriptor:command2" hidden="0">
<usages>
<usage>descriptor:command2 [-o|--option_name] [--] &lt;argument_name&gt;</usage>
<usage>descriptor:command2 -o|--option_name &lt;argument_name&gt;</usage>
Expand Down Expand Up @@ -168,6 +168,37 @@
</option>
</options>
</command>
<command id="descriptor:command3" name="descriptor:command3" hidden="1">
<usages>
<usage>descriptor:command3</usage>
</usages>
<description>command 3 description</description>
<help>command 3 help</help>
<arguments/>
<options>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this help message</description>
</option>
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not output any message</description>
</option>
<option name="--verbose" shortcut="-v" shortcuts="-v|-vv|-vvv" accept_value="0" is_value_required="0" is_multiple="0">
<description>Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug</description>
</option>
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
<description>Display this application version</description>
</option>
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Force ANSI output</description>
</option>
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>Disable ANSI output</description>
</option>
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
<description>Do not ask any interactive question</description>
</option>
</options>
</command>
</commands>
<namespaces>
<namespace id="_global">
Expand All @@ -179,6 +210,7 @@
<namespace id="descriptor">
<command>descriptor:command1</command>
<command>descriptor:command2</command>
<command>descriptor:command3</command>
</namespace>
</namespaces>
</symfony>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "descriptor:command1",
"hidden": false,
"usage": [
"descriptor:command1",
"alias1",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Tests/Fixtures/command_1.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<command id="descriptor:command1" name="descriptor:command1">
<command id="descriptor:command1" name="descriptor:command1" hidden="0">
<usages>
<usage>descriptor:command1</usage>
<usage>alias1</usage>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "descriptor:command2",
"hidden": false,
"usage": [
"descriptor:command2 [-o|--option_name] [--] <argument_name>",
"descriptor:command2 -o|--option_name <argument_name>",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Tests/Fixtures/command_2.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<command id="descriptor:command2" name="descriptor:command2">
<command id="descriptor:command2" name="descriptor:command2" hidden="0">
<usages>
<usage>descriptor:command2 [-o|--option_name] [--] &lt;argument_name&gt;</usage>
<usage>descriptor:command2 -o|--option_name &lt;argument_name&gt;</usage>
Expand Down