Skip to content

Commit

Permalink
feature #18790 [Console] Show aliases in command description instead …
Browse files Browse the repository at this point in the history
…of in different lines in application description (juanmirod)

This PR was squashed before being merged into the 3.2-dev branch (closes #18790).

Discussion
----------

[Console] Show aliases in command description instead of in different lines in application description

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18351
| License       | MIT
| Doc PR        |

This PR is a suggestion about the bug referenced in ticket 18351. The problem is that aliases create new lines with identical descriptions in the application description, it is suggested to show the aliases in the command description.

I had to modify one application fixture to meet this new behaviour and make the tests pass, but I don't think that a new application fixture is needed to test this having the application fixture 2.

Comments are welcome, this is my first PR in Symfony so if I need to meet any more requirements to make it correct to merge just tell me please.

Commits
-------

548ab0a [Console] Show aliases in command description instead of in different lines in application description
  • Loading branch information
fabpot committed Jun 8, 2016
2 parents 27f4680 + 548ab0a commit 4256b68
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
31 changes: 28 additions & 3 deletions src/Symfony/Component/Console/Descriptor/TextDescriptor.php
Expand Up @@ -198,16 +198,22 @@ protected function describeApplication(Application $application, array $options
}

// add commands by namespace
$commands = $description->getCommands();

foreach ($description->getNamespaces() as $namespace) {
if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
$this->writeText("\n");
$this->writeText(' <comment>'.$namespace['id'].'</comment>', $options);
}

foreach ($namespace['commands'] as $name) {
$this->writeText("\n");
$spacingWidth = $width - strlen($name);
$this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
if (isset($commands[$name])) {
$this->writeText("\n");
$spacingWidth = $width - strlen($name);
$command = $commands[$name];
$commandAliases = $this->getCommandAliasesText($command);
$this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options);
}
}
}

Expand All @@ -226,6 +232,25 @@ private function writeText($content, array $options = array())
);
}

/**
* Formats command aliases to show them in the command description.
*
* @param Command $command
*
* @return string
*/
private function getCommandAliasesText($command)
{
$text = '';
$aliases = $command->getAliases();

if ($aliases) {
$text = '['.implode('|', $aliases).'] ';
}

return $text;
}

/**
* Formats input option/argument default value.
*
Expand Down
Expand Up @@ -13,10 +13,8 @@
<info>-v|vv|vvv, --verbose</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

<comment>Available commands:</comment>
<info>alias1</info> command 1 description
<info>alias2</info> command 1 description
<info>help</info> Displays help for a command
<info>list</info> Lists commands
<comment>descriptor</comment>
<info>descriptor:command1</info> command 1 description
<info>descriptor:command1</info> [alias1|alias2] command 1 description
<info>descriptor:command2</info> command 2 description

0 comments on commit 4256b68

Please sign in to comment.