-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Command] Add question helper for unknown or ambiguous commands #19282
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
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
36 changes: 36 additions & 0 deletions
36
src/Symfony/Component/Console/Exception/AmbiguousCommandException.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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Exception; | ||
|
||
/** | ||
* @author Martin Hasoň <martin.hason@gmail.com> | ||
*/ | ||
class AmbiguousCommandException extends CommandNotFoundException | ||
{ | ||
private $command; | ||
|
||
public function __construct($command, $alternatives = array(), $code = null, $previous = null) | ||
{ | ||
$this->command = $command; | ||
$message = sprintf('Command "%s" is ambiguous (%s).', $command, $this->getAbbreviationSuggestions($alternatives)); | ||
|
||
parent::__construct($message, $alternatives, $code, $previous); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCommand() | ||
{ | ||
return $this->command; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/Symfony/Component/Console/Exception/AmbiguousNamespaceException.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,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Exception; | ||
|
||
/** | ||
* @author Martin Hasoň <martin.hason@gmail.com> | ||
*/ | ||
class AmbiguousNamespaceException extends CommandNotFoundException | ||
{ | ||
private $namespace; | ||
|
||
public function __construct($namespace, $alternatives = array(), $code = null, $previous = null) | ||
{ | ||
$this->command = $namespace; | ||
|
||
$message = sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions($alternatives)); | ||
|
||
parent::__construct($message, $alternatives, $code, $previous); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getNamespace() | ||
{ | ||
return $this->namespace; | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/Symfony/Component/Console/Exception/UnknownCommandException.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,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Exception; | ||
|
||
/** | ||
* @author Martin Hasoň <martin.hason@gmail.com> | ||
*/ | ||
class UnknownCommandException extends CommandNotFoundException | ||
{ | ||
private $command; | ||
|
||
public function __construct($command, $alternatives = array(), $code = null, $previous = null) | ||
{ | ||
$this->command = $command; | ||
|
||
$message = sprintf('Command "%s" is not defined.', $command); | ||
|
||
if ($alternatives) { | ||
if (1 == count($alternatives)) { | ||
$message .= "\n\nDid you mean this?\n "; | ||
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. I doubt the exception should format the message rendered in the console itself. Instead, consumers should build the formatted message IMO. |
||
} else { | ||
$message .= "\n\nDid you mean one of these?\n "; | ||
} | ||
|
||
$message .= implode("\n ", $alternatives); | ||
} | ||
|
||
parent::__construct($message, $alternatives, $code, $previous); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCommand() | ||
{ | ||
return $this->command; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Symfony/Component/Console/Exception/UnknownNamespaceException.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,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Exception; | ||
|
||
/** | ||
* @author Martin Hasoň <martin.hason@gmail.com> | ||
*/ | ||
class UnknownNamespaceException extends CommandNotFoundException | ||
{ | ||
private $namespace; | ||
|
||
public function __construct($namespace, $alternatives = array(), $code = null, $previous = null) | ||
{ | ||
$this->namespace = $namespace; | ||
|
||
$message = sprintf('There are no commands defined in the "%s" namespace.', $namespace); | ||
|
||
if ($alternatives) { | ||
if (1 == count($alternatives)) { | ||
$message .= "\n\nDid you mean this?\n "; | ||
} else { | ||
$message .= "\n\nDid you mean one of these?\n "; | ||
} | ||
|
||
$message .= implode("\n ", $alternatives); | ||
} | ||
|
||
parent::__construct($message, $alternatives, $code, $previous); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getNamespace() | ||
{ | ||
return $this->namespace; | ||
} | ||
} |
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
8 changes: 4 additions & 4 deletions
8
src/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
[Symfony\Component\Console\Exception\CommandNotFoundException] | ||
Command "foo" is not defined. | ||
|
||
[Symfony\Component\Console\Exception\UnknownCommandException] | ||
Command "foo" is not defined. | ||
|
||
|
10 changes: 5 additions & 5 deletions
10
src/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
[Symfony\Component\Console\Exception\CommandNotFoundException] | ||
Command "foo" is not define | ||
d. | ||
|
||
[Symfony\Component\Console\Exception\UnknownCommandException] | ||
Command "foo" is not define | ||
d. | ||
|
||
|
10 changes: 10 additions & 0 deletions
10
src/Symfony/Component/Console/Tests/Fixtures/application_unknown_command_question.txt
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,10 @@ | ||
Command "foo" is not defined. Please select one of these suggested commands: | ||
[0] foo:bar1 | ||
[1] foo:bar | ||
[2] foo1:bar | ||
[3] afoobar | ||
[4] afoobar1 | ||
[5] afoobar2 | ||
> 1[K | ||
interact called | ||
called |
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.
typo
$this->namespace = $namespace;