Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Conversation

@pierredup
Copy link
Contributor

@pierreduppierredup commentedJan 9, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed tickets
LicenseMIT
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 command

console

apfelbox, smithandre, TomasVotruba, and antoinearrive reacted with thumbs up emoji
@pierreduppierredupforce-pushed theconsole-run-command-suggestion branch frome8f9bdf to5abc30fCompareJanuary 9, 2018 14:02
@nicolas-grekasnicolas-grekas added this to the4.1 milestoneJan 9, 2018
@pierreduppierredup changed the title[Console] Add options to automatically run suggested command if there is only 1 alternative[Console] Add option to automatically run suggested command if there is only 1 alternativeJan 9, 2018
@pierreduppierredupforce-pushed theconsole-run-command-suggestion branch 2 times, most recently from3524d9d tobc36d20CompareJanuary 9, 2018 20:26
*/
class NamespaceNotFoundExceptionextends CommandNotFoundException
{
}
Copy link
Member

@chalasrchalasrJan 11, 2018
edited
Loading

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).

Copy link
ContributorAuthor

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
Copy link
Member

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()) {
Copy link
Member

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`
Copy link
Member

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:
Copy link
Member

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

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Addressed in#25794

chalasr reacted with thumbs up emoji
$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;
Copy link
Member

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
Copy link
Member

chalasr commentedJan 12, 2018
edited
Loading

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

How that? AFAIU it behaves the same for both exceptions currently

@fabpot
Copy link
Member

@pierredup Can you rebase to get rid of the merge commit? We never merge a PR with a merge commit. Thanks.

@pierreduppierredupforce-pushed theconsole-run-command-suggestion branch from6e93303 to222af7cCompareJanuary 23, 2018 06:36
@pierreduppierredupforce-pushed theconsole-run-command-suggestion branch from222af7c toe4deda7CompareJanuary 23, 2018 06:38
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()) {
Copy link
Member

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

Copy link
ContributorAuthor

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)

Copy link
ContributorAuthor

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);
Copy link
Member

@chalasrchalasrFeb 8, 2018
edited
Loading

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 wrong line

$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"');
Copy link
Member

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)

Copy link
Member

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)) {
Copy link
Member

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
Copy link
Member

@pierredup Can you look at the failing tests? looks like a spacing issue.

@pierredup
Copy link
ContributorAuthor

New failures on travis seems unrelated

@fabpot
Copy link
Member

Thank you@pierredup.

@fabpotfabpot closed thisFeb 22, 2018
fabpot added a commit that referenced this pull requestFeb 22, 2018
…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 command![console](https://user-images.githubusercontent.com/144858/34724377-4b46c726-f556-11e7-94a3-a9d7c9d75e74.gif)Commits-------83d52f0 [Console] Add option to automatically run suggested command if there is only 1 alternative
@pierreduppierredup deleted the console-run-command-suggestion branchFebruary 22, 2018 06:50
@fabpotfabpot mentioned this pull requestMay 7, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chalasrchalasrchalasr requested changes

@fabpotfabpotfabpot approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

5 participants

@pierredup@chalasr@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp