-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Define constants for main exit codes. #35431
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
Comments
you can define such consts in your application for your commands, i dont think it's much of value for core commands, nor is implying everyone should use this. Personally im fine with ints :) IMHO it's the same topic as http status codes => #22023 |
@ro0NL this is indeed a similar situation to the constants for the HTTP Status Codes. We rejected to use those in Symfony's own code ... but we defined those constants in case developers want to use them in their apps (I do for example 😊). My opinion: I'd love to have these constants for command exit codes. Not for all the codes defined here, but for the most common: symfony/src/Symfony/Component/Process/Process.php Lines 88 to 95 in e0c1f4d
Why? Because I always have problems remembering if "success exit" is |
@javiereguiluz do you know any real use cases where a command returns status greater than |
i was a bit skeptical about consts for just int(0) or int(1), having more defined exit codes is more valueable 👍 personally i dont think of im also curious if it belongs to Process or Console component :D |
@Chi-teck although it's hard to find a standard list of exit codes ... most Linux-flavored OS use these codes: https://github.com/freebsd/freebsd/blob/master/include/sysexits.h Some of them are useful to us: |
Great move! I'd go with success/failure only for a start. I use similar approach for ~ 2 years: Inspired by @cakephp |
I would start with only two constants for the following reasons.
|
I agree that we should only have constants for 0 and 1. |
This PR was squashed before being merged into the 5.1-dev branch (closes #35478). Discussion ---------- [Console] Add constants for main exit codes | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? |no | Tickets | Fix #35431 | License | MIT Commits ------- 5f6a1ac [Console] Add constants for main exit codes
…possible (me) This PR was merged into the 1.0-dev branch. Discussion ---------- Use Command:SUCCESS constant for command exit code when possible This is follow-up for symfony/symfony#35431 It would also align generated code with an example in the documentation. https://symfony.com/doc/current/console.html#creating-a-command Commits ------- d40ec33 Use Command:SUCCESS constant for command exit code when possible
…possible (me) This PR was merged into the 1.0-dev branch. Discussion ---------- Use Command:SUCCESS constant for command exit code when possible This is follow-up for symfony/symfony#35431 It would also align generated code with an example in the documentation. https://symfony.com/doc/current/console.html#creating-a-command Commits ------- d40ec33 Use Command:SUCCESS constant for command exit code when possible
Description
Console commands must return exit code. I propose we define constants for most used exit statuses like it is done in C programming language.
https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
That would make code a bit more clear.
Example
Before:
return 0;
After:
return self::EXIT_SUCCESS;
The text was updated successfully, but these errors were encountered: