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 urfave/cli as a code owner Sep 8, 2020
@knqyf263 knqyf263 requested review from rliebz and asahasrabuddhe and removed request for urfave/cli Sep 8, 2020
@rliebz
Copy link
Member

@rliebz 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 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?

@rliebz
rliebz approved these changes Oct 22, 2020
Copy link
Member

@rliebz rliebz left a comment

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

LGTM

@rliebz rliebz merged commit d89733e into urfave:master Oct 31, 2020
10 of 12 checks passed
10 of 12 checks passed
ubuntu-latest @ Go 1.12
Details
ubuntu-latest @ Go 1.13
Details
ubuntu-latest @ Go 1.14
Details
macos-latest @ Go 1.12
Details
macos-latest @ Go 1.13
Details
macos-latest @ Go 1.14
Details
windows-latest @ Go 1.12
Details
windows-latest @ Go 1.13
Details
windows-latest @ Go 1.14
Details
test-docs
Details
codecov/patch Codecov Report
Details
codecov/project Codecov Report
Details
@knqyf263 knqyf263 deleted the knqyf263:feat/subcommand_help_and_exit branch Nov 1, 2020
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.

3 participants