Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Console] Add option to automatically run suggested command if there is only 1 alternative#25732
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
e8f9bdf to5abc30fCompare3524d9d tobc36d20Compare| */ | ||
| class NamespaceNotFoundExceptionextends CommandNotFoundException | ||
| { | ||
| } |
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.
This addition is not strictly needed, right? Not sure it's useful, and it involves a BC break with no upgrade path in the future (stop extendingCommandNotFoundException, new unhandled exceptions in userland).
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.
No it's not strictly needed, but I needed a way to distinguish between not finding a namespace and not finding a command to prevent incorrect suggestions when typing an incorrect namespace. Keeping this class extending fromCommandNotFound seemed weird as they are for different use cases, which is why I added the deprecation
| * | ||
| * @author Pierre du Plessis <pdples@gmail.com> | ||
| * | ||
| * @deprecated This class won't extend CommandNotFoundException in Symfony 5 |
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.
@deprecated should only be used when a class is actually deprecated, the debug class loader parses such annotations, could lead to wrong notices e.g. when extending it.
| } | ||
| throw$e; | ||
| if (!($einstanceof CommandNotFoundException && !$einstanceof NamespaceNotFoundException) ||1 !==count($alternatives =$e->getAlternatives()) || !$input->isInteractive()) { |
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.
Doing this here keeps dispatching a console.error event, not sure it's desired in case the user choose to run the single alternative? Especially given it's currently not taking into account the potential changes made on the event (see comment below)
| * removed`ConsoleExceptionEvent` | ||
| * removed`ConsoleEvents::EXCEPTION` | ||
| * removed`ConsoleExceptionEvent` | ||
| * removed`ConsoleEvents::EXCEPTION` |
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.
please revert, should be done on 3.4
| @@ -1,5 +1,5 @@ | |||
| In ApplicationTest.php line770: | |||
| In ApplicationTest.php line795: | |||
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.
Going to be a nightmare, we should make the related tests more flexible by using a placeholder where they have been introduced
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.
Addressed in#25794
| $question =newConfirmationQuestion(sprintf("<error>Command\"%s\" is not defined.</error>\n\nDo you want to run\"%s\" instead? [y/n]",$name,$alternative),false); | ||
| if (!(newQuestionHelper())->ask($input,$output,$question)) { | ||
| return1; |
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 error event allows to set a custom exit code and override the exception, it must keep working
chalasr commentedJan 12, 2018 • 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.
How that? AFAIU it behaves the same for both exceptions currently |
6c1cd01 to34222d7Comparefabpot commentedJan 23, 2018
@pierredup Can you rebase to get rid of the merge commit? We never merge a PR with a merge commit. Thanks. |
6e93303 to222af7cCompare222af7c toe4deda7Compare| if (null !==$this->dispatcher) { | ||
| $event =newConsoleErrorEvent($input,$output,$e); | ||
| $this->dispatcher->dispatch(ConsoleEvents::ERROR,$event); | ||
| if (!($einstanceof CommandNotFoundException && !$einstanceof NamespaceNotFoundException) ||1 !==count($alternatives =$e->getAlternatives()) || !$input->isInteractive()) { |
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.
This proposes to run the alternative even if it's a namespace only, right? A test case would be good to make sure it does not
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.
No, if it's a namespace only then the behaviour stays unchanged (Which would giving you an error and giving a list suggested namespaces without the option to run a command)
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.
Added another test case to cover namespace error
| return1; | ||
| } | ||
| $command =$this->find($alternative); |
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 to use wrong lineSymfonyStyle instead
| $this->assertRegExp('/There are no commands defined in the "foo2" namespace./',$e->getMessage(),'->find() throws aCommandNotFoundException if namespace does not exist, with alternative'); | ||
| $this->assertRegExp('/foo/',$e->getMessage(),'->find() throws aCommandNotFoundException if namespace does not exist, with alternative : "foo"'); | ||
| $this->assertRegExp('/foo1/',$e->getMessage(),'->find() throws aCommandNotFoundException if namespace does not exist, with alternative : "foo1"'); | ||
| $this->assertRegExp('/foo3/',$e->getMessage(),'->find() throws aCommandNotFoundException if namespace does not exist, with alternative : "foo3"'); |
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.
They are still valid and ensure the new class keeps extending it (prevent a BC break)
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 revert and only add a new assertion, avoiding merge conflicts
| $alternative =$alternatives[0]; | ||
| $question =newConfirmationQuestion(sprintf("<error>Command\"%s\" is not defined.</error>\n\nDo you want to run\"%s\" instead? [y/n]",$name,$alternative),false); | ||
| if (!(newQuestionHelper())->ask($input,$output,$question)) { |
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 to useSymfonyStyle instead
chalasr commentedFeb 17, 2018
@pierredup Can you look at the failing tests? looks like a spacing issue. |
pierredup commentedFeb 22, 2018
New failures on travis seems unrelated |
fabpot commentedFeb 22, 2018
Thank you@pierredup. |
…mmand if there is only 1 alternative (pierredup)This PR was squashed before being merged into the 4.1-dev branch (closes#25732).Discussion----------[Console] Add option to automatically run suggested command if there is only 1 alternative| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | yes| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR |When mistyping a console command, you get an error giving suggested commands.If there is only 1 alternative suggestion, this PR will give you the option to run that command instead. This makes it easier to run the correct command without having to re-type/copy-paste/update the previous run commandCommits-------83d52f0 [Console] Add option to automatically run suggested command if there is only 1 alternative
Uh oh!
There was an error while loading.Please reload this page.
When mistyping a console command, you get an error giving suggested commands.
If there is only 1 alternative suggestion, this PR will give you the option to run that command instead. This makes it easier to run the correct command without having to re-type/copy-paste/update the previous run command