Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Sort alternatives alphabetically when a command is not found#19887
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
javiereguiluz commentedSep 8, 2016
| Q | A |
|---|---|
| Branch? | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #10893 |
| License | MIT |
| Doc PR | - |
fabpot commentedSep 8, 2016
As we are listing alternatives in a lot of different places in the framework, wouldn't it make sense to change the sort for all of them? |
| 'afoobar', | ||
| 'afoobar1', | ||
| 'afoobar2', | ||
| 'foo1:bar', |
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 would have expected foo1:bar to be after foo:bar as intuitively, I sort the namespace first, then the command name. Not sure if this is something we need to fix though.
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.
That's probably because of the: when sorting
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 do understand that, my point is that we need to take care of that: when sorting like a human would do.
javiereguiluzSep 14, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
The good thing is that in real apps we probably won't have this problem. This example (foo:,foo1:,foo3:) is too abstract and probably our users don't useproject:,project1: orapp:,app1: namespaces.
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.
fair enough
fabpot commentedSep 14, 2016
Have you had time to have a look at the other exceptions using alternatives to see if sorting them would also make sense? |
ro0NL commentedSep 17, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I thought of this yesterday, and it's more or less related; wouldn't it be nice to filter the command list if a command is not found? Ie. |
fabpot commentedNov 9, 2016
@javiereguiluz Any news? |
fabpot commentedMar 1, 2017
@javiereguiluz Still interested in finishing this PR? |
javiereguiluz commentedMar 1, 2017
Yes ... but I don't know where to look for more places where this feature could be implemented. Anyone can give me a clue? Thanks! |
fabpot commentedMar 1, 2017
I think looking for |
javiereguiluz commentedMar 6, 2017
I've committed some changes:
|
| if (false !==strpos($definedTag,$tag) ||levenshtein($tag,$definedTag) <=strlen($tag) /3) { | ||
| $candidates[] =$definedTag; | ||
| if (false !==strpos($definedTag,$tag) ||$lev =levenshtein($tag,$definedTag) <=strlen($tag) /3) { | ||
| $candidates[$definedTag] =$lev; |
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.
why not just$candidates[$definedTag] = true;? That would avoid creating the$lev variable that is not used anyway.
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 about this.$lev is the score ... and we need that for the two new lines added below to sort results from best to worst:
asort($candidates);$candidates =array_keys($candidates);
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.
ok
fabpot commentedMar 14, 2017
Tests fail on deps=low, we should find a way to fix that. |
javiereguiluz commentedMar 19, 2017
I can't see which is the error that makes test fail for "deps = low". Can anyone help me? Thanks! Some context --> The original test was: But after this PR, that fails on most Symfony versions, so I changed it to: and now test pass ... except when using "deps = low", which fails because the expected output is again: |
linaori commentedMar 19, 2017
@javiereguiluz my guess is that the DependencyInjection needs a higher console version for that as it seems like it's the DependencyInjection component that fails. I could be wrong though, but that's my hunch after seeing the failure. |
javiereguiluz commentedMar 22, 2017
After thinking about this, what if we do the following:
Reason: We already show very good alternatives because we limit the levenhstein cost to < 3, so every alternative displayed is almost as good as the other ones. The proposed changes wouldn't make the results much better. What do you think? |
fabpot commentedMar 22, 2017
Make sense 👍 |
fabpot commentedMar 22, 2017
Thank you@javiereguiluz. |
… found (javiereguiluz)This PR was squashed before being merged into the 3.3-dev branch (closes#19887).Discussion----------Sort alternatives alphabetically when a command is not found| Q | A || --- | --- || Branch? | master || Bug fix? | no || New feature? | yes || BC breaks? | no || Deprecations? | no || Tests pass? | yes || Fixed tickets |#10893 || License | MIT || Doc PR | - |Commits-------ba6c946 Sort commands like a human would dof04b1bd Sort alternatives alphabetically when a command is not found