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

feat(help): add ShowSubcommandHelpAndExit #1183

Merged
merged 1 commit into from Oct 31, 2020

Conversation

knqyf263
Copy link
Contributor

@knqyf263 knqyf263 commented Sep 8, 2020

What type of PR is this?

  • bug
  • cleanup
  • documentation
  • feature

What this PR does / why we need it:

  • Add ShowSubcommandHelpAndExit to help.go
  • It is also useful like ShowCommandHelpAndExit and ShowAppHelpAndExit

Which issue(s) this PR fixes:

Fixes #1112

Special notes for your reviewer:

I didn't find any test for XXXHelpAndExit.

Testing

I prepared a sample program.

Release Notes

Added ShowSubcommandHelpAndExit to print help for the given subcommand and exit with exit code.

@knqyf263 knqyf263 requested a review from a team as a code owner September 8, 2020 14:59
@knqyf263 knqyf263 requested review from rliebz and asahasrabuddhe and removed request for a team September 8, 2020 14:59
@rliebz
Copy link
Member

rliebz commented Oct 3, 2020

I'm not a huge fan of increasing the surface area of the public API here to turn a two-liner into a one-liner.

Is there a reason why doing these calls manually is problematic?

@knqyf263
Copy link
Contributor Author

knqyf263 commented Oct 5, 2020

This is because urfave/cli already has the following public APIs. I think they are useful even though it turns a two-liner into a one-liner.

cli/help.go

Lines 67 to 71 in 74af85a

// ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code.
func ShowAppHelpAndExit(c *Context, exitCode int) {
_ = ShowAppHelp(c)
os.Exit(exitCode)
}

cli/help.go

Lines 182 to 186 in 74af85a

// ShowCommandHelpAndExit - exits with code after showing help
func ShowCommandHelpAndExit(c *Context, command string, code int) {
_ = ShowCommandHelp(c, command)
os.Exit(code)
}

If ShowSubcommandHelpAndExit doesn't make sense, I feel like the above APIs also don't make sense, just reducing one line. I thought they are the same, but is there any difference between ShowSubcommandHelp and ShowCommandHelp?

Copy link
Member

@rliebz rliebz left a comment

Choose a reason for hiding this comment

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

Sorry for the delay here. You're right—having 2/3 of these functions is an obvious omission.

Thanks for the contribution!

Copy link
Member

@asahasrabuddhe asahasrabuddhe left a comment

Choose a reason for hiding this comment

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

LGTM

@rliebz rliebz merged commit d89733e into urfave:master Oct 31, 2020
@knqyf263 knqyf263 deleted the feat/subcommand_help_and_exit branch November 1, 2020 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a ShowSubcommandHelpAndExit()
3 participants