Skip to content

[Console] Improve UX on not found namespace/command #20869

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
Dec 13, 2016

Conversation

Seldaek
Copy link
Member

@Seldaek Seldaek commented Dec 11, 2016

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

This improves the DX/UX when you don't remember what a command is called.. Traditionally you get this message saying "command x is ambiguous (Y, Z or 6 more)" and if the one you are looking for is in the 6 more you are out of luck. You then have to run the console without arg again, get 50 commands displayed, then have to scroll up to find which one it is you meant.

With this patch you get all suggestions always, even with description, so you can make an informed decision right away. See before/after on the screenshot below.

image

@linaori
Copy link
Contributor

linaori commented Dec 11, 2016

Seems a lot better! Is it possible to make a 2 column table (borderless) out of them so they align properly?

@Seldaek
Copy link
Member Author

Seldaek commented Dec 11, 2016

Yup, did it by hand because it's like 3 lines of code and the Table requires an output and all.. seemed overly complex for this.

image

@Seldaek Seldaek force-pushed the console_ux branch 2 times, most recently from 76ecf4d to 70b3e00 Compare December 11, 2016 13:53
public function testFindAmbiguousNamespace()
{
$application = new Application();
$application->add(new \BarBucCommand());
$application->add(new \FooCommand());
$application->add(new \Foo2Command());

$expectedMsg = "The namespace \"f\" is ambiguous.\nDid you mean one of these?\n foo\n foo1";
$this->setExpectedException('Symfony\Component\Console\Exception\CommandNotFoundException', $expectedMsg);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe you can use ::class there instead of the string? As the target is master this should be alright

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 12, 2016
@@ -559,9 +559,20 @@ public function find($name)

$exact = in_array($name, $commands, true);
if (count($commands) > 1 && !$exact) {
$suggestions = $this->getAbbreviationSuggestions(array_values($commands));
$usableWidth = ($this->terminal->getWidth() ?: 60) - 10;
Copy link
Member

Choose a reason for hiding this comment

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

getWidth always returns something, with a default of 80

$abbrevs = array_values($commands);
$maxLen = 0;
foreach ($abbrevs as $abbrev) {
$maxLen = max(strlen($abbrev), $maxLen);
Copy link
Member

Choose a reason for hiding this comment

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

you should use Helper::strlen to deal with UTF-8 properly

$abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen) {
$abbrev = str_pad($cmd, $maxLen, ' ').' '.$commandList[$cmd]->getDescription();

return strlen($abbrev) > $usableWidth ? substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev;
Copy link
Member

Choose a reason for hiding this comment

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

Helper::strlen

@nicolas-grekas nicolas-grekas modified the milestones: 3.3, 3.x Dec 12, 2016
@hason
Copy link
Contributor

hason commented Dec 12, 2016

What about combine with PR #19282?

@Seldaek
Copy link
Member Author

Seldaek commented Dec 12, 2016

Fixed feedback (I had to add a Helper::substr too, I hope that's ok).

@hason hmm yeah I guess if yours is merged it kinda makes this one obsolete anyway? I don't really have a preference, I guess this one is simpler but less powerful.

@fabpot
Copy link
Member

fabpot commented Dec 13, 2016

Thank you @Seldaek.

@fabpot fabpot merged commit aae5fb1 into symfony:master Dec 13, 2016
fabpot added a commit that referenced this pull request Dec 13, 2016
…eldaek)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Console] Improve UX on not found namespace/command

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

This improves the DX/UX when you don't remember what a command is called.. Traditionally you get this message saying "command x is ambiguous (Y, Z or 6 more)" and if the one you are looking for is in the 6 more you are out of luck. You then have to run the console without arg again, get 50 commands displayed, then have to scroll up to find which one it is you meant.

With this patch you get all suggestions always, even with description, so you can make an informed decision right away. See before/after on the screenshot below.

![image](https://cloud.githubusercontent.com/assets/183678/21080350/c3d446ea-bfac-11e6-934b-ba3d7c3dd34d.png)

Commits
-------

aae5fb1 Improve UX on not found namespace/command
@fabpot fabpot mentioned this pull request May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants