-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] command list ordering, styles in command names bugfix #12051 #12500
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,15 +134,17 @@ private function inspectApplication() | |
private function sortCommands(array $commands) | ||
{ | ||
$namespacedCommands = array(); | ||
$globalCommands = array(); | ||
foreach ($commands as $name => $command) { | ||
$key = $this->application->extractNamespace($name, 1); | ||
if (!$key) { | ||
$key = '_global'; | ||
$globalCommands['_global'][$name] = $command; | ||
} else { | ||
$namespacedCommands[$key][$name] = $command; | ||
} | ||
|
||
$namespacedCommands[$key][$name] = $command; | ||
} | ||
ksort($namespacedCommands); | ||
$namespacedCommands = array_merge($globalCommands, $namespacedCommands); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some unit tests to cover the cases explained in the ticket? |
||
foreach ($namespacedCommands as &$commands) { | ||
ksort($commands); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,13 +195,15 @@ protected function describeApplication(Application $application, array $options | |
// add commands by namespace | ||
foreach ($description->getNamespaces() as $namespace) { | ||
if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { | ||
$this->writeText("\n"); | ||
$this->writeText('<comment>'.$namespace['id'].'</comment>', $options); | ||
$this->writeText("\n<comment>", $options); | ||
$this->writeText($namespace['id'], array_merge($options, array('raw_output' => true))); | ||
$this->writeText("</comment>", $options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also be tested |
||
} | ||
|
||
foreach ($namespace['commands'] as $name) { | ||
$this->writeText("\n"); | ||
$this->writeText(sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options); | ||
$this->writeText("\n <info>", $options); | ||
$this->writeText(sprintf("%-${width}s", $name), array_merge($options, array('raw_output' => true))); | ||
$this->writeText(sprintf("</info> %s", $description->getCommand($name)->getDescription()), $options); | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Symfony/Component/Console/Tests/Fixtures/Foo6Command.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
|
||
use Symfony\Component\Console\Command\Command; | ||
|
||
class Foo6Command extends Command | ||
{ | ||
protected function configure() | ||
{ | ||
$this->setName('<fg=blue>foo:bar</fg=blue>'); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest the
_global
key here, build$globalCommands
as being only the array of global commands themselves, and the prepending this array in the list of commands after the sorting witharray_shift($namespacedCommands, $globalCommands)
(and doing it only in case the list of global commands is not empty to avoid useless work)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, actually no. The switch from array_merge to array_shift won't work because the code expects to have a _global key for global commands. But the global key could be handle at the time of merging, keeping
$globalCommands
as the list of global commands (which is not the case currently)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you meant here. Anyway I know that
$globalCommands['_global']
feels redunant but in my opinion is it fine. Thearray_merge
call later looks pretty straightforward this way.