Sitelet https://web.archive.org/web/20200920215810/https://github.com/urfave/cli/pull/1163
Skip to content
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

make missing required flags an ExitCoder so that app exit code handling treats this as an error #1163

Open
wants to merge 1 commit into
base: v1
from

Conversation

@cmstrickland
Copy link

cmstrickland commented Jul 22, 2020

What type of PR is this?

  • bug
  • cleanup
  • documentation
  • feature

What this PR does / why we need it:

modifies errRequiredFlags so that it can be used as an ExitCoder, and then changes the error handling in app.Run so that it does not bypass the osExit handling

Special notes for your reviewer:

I just picked a value to use for the exit status, it is hard coded
This patch is only against v1, I am not currently using v2, unsure if it is applicable there.

Testing

I added a simple test to app_test that the handler is called when a required flag is not supplied

Release Notes

if a flag is defined as Required but is not present, app.Run will call os.Exit with 127 

extend app.Run() such that missing flags that are set as Required will
be handled by OSExiter

defines a fixed error status for missing default flags
extends the requiredFlagsErr interface to satisfy ExitCoder()
implement ExitCode() on errRequiredFlags struct to return the fixed
error status

then when App is checking requiredFlags, call handleExitCoder if there
is an error returned here
@cmstrickland cmstrickland requested a review from urfave/cli as a code owner Jul 22, 2020
@cmstrickland cmstrickland requested review from saschagrunert and rliebz Jul 22, 2020
Copy link
Member

saschagrunert left a comment

LGTM :)

Copy link
Member

lynncyrin left a comment

v1 is in maintenance mode and this is a very very small new feature, and a potentially breaking one at that. So I'm not sure it's good idea for us to merge this.

I could be convinced otherwise, though!

@cmstrickland
Copy link
Author

cmstrickland commented Jul 28, 2020

v1 is in maintenance mode and this is a very very small new feature, and a potentially breaking one at that. So I'm not sure it's good idea for us to merge this.

I could be convinced otherwise, though!

Thank you for the review! I can understand this point of view. I don't think this changes is much of a breaking one though, specific to this case, Required attribute is quite recent feature addition to 1.x (I think it is introduced with 1.22.1 flag rework)

I do find it difficult to imagine who is relying on the specific implementation of required flags, particularly in expecting a successful exit code for an failure to run, but this is the nature of changing anything established, there's no way to predict every user's expectations, I grant. I am quite happy for it to be either merged or closed, and once again, thanks for your time and efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.