Skip to content

[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

Merged
merged 1 commit into from
Aug 31, 2014

Conversation

tPl0ch
Copy link

@tPl0ch tPl0ch commented Oct 7, 2013

Use case: We have different variations of the same application, for which
only certain commands are allowed. Right now this is done in a custom
Application class, but it would be much easier to just be able to skip
commands from a listener, where you can disable commands via the Event
object.

This patch provides this feature and corresponding test cases.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes - for Console tests
Fixed tickets None
License MIT
Doc PR symfony/symfony-docs#4058

/**
* The return code for skipped commands, this will also be passed into the terminate event
*/
const RETURN_CODE_DISABLED = -1024;
Copy link
Member

Choose a reason for hiding this comment

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

This is not a valid exist code (http://www.tldp.org/LDP/abs/html/exitcodes.html).

Use case: We have different variations of the same application, for which
only certain commands are allowed. Right now this is done in a custom
Application class, but it would be much easier to just be able to skip
commands from a listener, where you can disable commands via the Event
object.

This patch provides this feature and corresponding test cases.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes - for Console tests
| Fixed tickets | None
| License       | MIT
| Doc PR        | None
@tPl0ch
Copy link
Author

tPl0ch commented Jul 25, 2014

@fabpot I now use return code 113, which is in the recommended range for user-specified return codes in the document you linked to. Commits have been rebased to current master.

@fabpot
Copy link
Member

fabpot commented Jul 25, 2014

👍 Can you create a PR on the docs as well?

/**
* The return code for skipped commands, this will also be passed into the terminate event
*/
const RETURN_CODE_DISABLED = 113;
Copy link
Member

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.

Copy link
Author

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.

tPl0ch pushed a commit to tPl0ch/symfony-docs that referenced this pull request Jul 25, 2014
| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#9235)
| Applies to    | master
| Fixed tickets | none
@tPl0ch
Copy link
Author

tPl0ch commented Jul 25, 2014

@fabpot Created PR on the docs :)

tPl0ch pushed a commit to tPl0ch/symfony-docs that referenced this pull request Jul 25, 2014
| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#9235)
| Applies to    | master
| Fixed tickets | none
tPl0ch pushed a commit to tPl0ch/symfony-docs that referenced this pull request Jul 25, 2014
| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#9235)
| Applies to    | master
| Fixed tickets | none
tPl0ch pushed a commit to tPl0ch/symfony-docs that referenced this pull request Jul 25, 2014
| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#9235)
| Applies to    | master
| Fixed tickets | none
@fabpot
Copy link
Member

fabpot commented Aug 31, 2014

Thank you @tPl0ch.

@fabpot fabpot merged commit acb1ae6 into symfony:master Aug 31, 2014
fabpot added a commit that referenced this pull request Aug 31, 2014
This PR was merged into the 2.6-dev branch.

Discussion
----------

[Console] Skip commands from ConsoleCommandEvent

Use case: We have different variations of the same application, for which
only certain commands are allowed. Right now this is done in a custom
Application class, but it would be much easier to just be able to skip
commands from a listener, where you can disable commands via the Event
object.

This patch provides this feature and corresponding test cases.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes - for Console tests
| Fixed tickets | None
| License       | MIT
| Doc PR        | symfony/symfony-docs#4058

Commits
-------

acb1ae6 [Console] Skip commands from ConsoleCommandEvent
*
* @return bool
*/
public function commandShouldRun()
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the return code is named _DISABLED. maybe this method should be called commandIsDisabled()?

@Tobion
Copy link
Contributor

Tobion commented Aug 31, 2014

The disabled commands are still listed in the help. But when you call them, it won't work. So I dislike the implementation at this stage. 👎

@tPl0ch
Copy link
Author

tPl0ch commented Aug 31, 2014

@Tobion Well, commands are registered during compile time, and this feature is making it possible to disable a command during run time, i.e. because an important resource is locked or some other restrictions apply. The only thing I can see is making the failure more explicit by throwing sth. like a CommandWasDisabledException, where you could provide more information on why that command has failed.

@Tobion
Copy link
Contributor

Tobion commented Aug 31, 2014

I'm saying disabled commands should either not be listed or mention that they are currently disabled.

weaverryan added a commit to symfony/symfony-docs that referenced this pull request Nov 4, 2014
This PR was merged into the master branch.

Discussion
----------

Skip console commands from event listeners

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#9235)
| Applies to    | master
| Fixed tickets | none

Commits
-------

cb508f7 [WCM] Skip console commands from event listeners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants