-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Skip commands from ConsoleCommandEvent #9235
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,51 @@ | |
namespace Symfony\Component\Console\Event; | ||
|
||
/** | ||
* Allows to do things before the command is executed. | ||
* Allows to do things before the command is executed, like skipping the command or changing the input. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
*/ | ||
class ConsoleCommandEvent extends ConsoleEvent | ||
{ | ||
/** | ||
* The return code for skipped commands, this will also be passed into the terminate event | ||
*/ | ||
const RETURN_CODE_DISABLED = 113; | ||
|
||
/** | ||
* Indicates if the command should be run or skipped | ||
* | ||
* @var bool | ||
*/ | ||
private $commandShouldRun = true; | ||
|
||
/** | ||
* Disables the command, so it won't be run | ||
* | ||
* @return bool | ||
*/ | ||
public function disableCommand() | ||
{ | ||
return $this->commandShouldRun = false; | ||
} | ||
|
||
/** | ||
* Enables the command | ||
* | ||
* @return bool | ||
*/ | ||
public function enableCommand() | ||
{ | ||
return $this->commandShouldRun = true; | ||
} | ||
|
||
/** | ||
* Returns true if the command is runnable, false otherwise | ||
* | ||
* @return bool | ||
*/ | ||
public function commandShouldRun() | ||
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. should is the wrong term. if "should" says no, it doesn't mean it's not allowed to run. but that is what it is used for. 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. Since the return code is named |
||
{ | ||
return $this->commandShouldRun; | ||
} | ||
} |
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
113
?I think this constant should be defined in
Application
class because it is used in it and makes the return code of the application.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.
@GromNaN http://www.tldp.org/LDP/abs/html/exitcodes.html @fabpot pointed me to this document, and there the author recommends the return codes within the range 64-113, and I am a kind of max guy, so I chose the upper range limit.