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

Add a ShowSubcommandHelpAndExit() #1112

Closed
3 tasks done
bodgit opened this issue Apr 24, 2020 · 4 comments · Fixed by #1183
Closed
3 tasks done

Add a ShowSubcommandHelpAndExit() #1112

bodgit opened this issue Apr 24, 2020 · 4 comments · Fixed by #1183
Labels
area/v2 relates to / is being considered for v2 kind/feature describes a code enhancement / feature request status/triage maintainers still need to look into this

Comments

@bodgit
Copy link

bodgit commented Apr 24, 2020

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this feature? Here's the Github guide about searching.

What problem does this solve?

There is a ShowAppHelpAndExit() and a ShowCommandHelpAndExit() but there's currently no ShowSubcommandHelpAndExit().

Solution description

I usually use at the top of my command actions something like this:

if c.NArg() < 2 {
        cli.ShowCommandHelpAndExit(c, c.Command.FullName(), 1)
}

So if someone doesn't supply the correct number of positional arguments they get the help and it exits with a non-zero code.

I tried to use sub-commands for the first time and found I can't do this.

Describe alternatives you've considered

I've tried implementing as:

if c.NArg() < 2 {
        cli.ShowSubcommandHelp(c)
        return cli.NewExitError(nil, 1)
}

but that doesn't work very well.

@bodgit bodgit added area/v2 relates to / is being considered for v2 status/triage maintainers still need to look into this labels Apr 24, 2020
@coilysiren
Copy link
Member

@bodgit what about your alternative doesn't work very well?

@stale
Copy link

stale bot commented Aug 2, 2020

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Aug 2, 2020
@stale
Copy link

stale bot commented Sep 2, 2020

Closing this as it has become stale.

@stale stale bot closed this as completed Sep 2, 2020
@meatballhat meatballhat reopened this Apr 22, 2022
@meatballhat meatballhat removed the status/stale stale due to the age of it's last update label Apr 22, 2022
@meatballhat meatballhat changed the title v2 feature: add a ShowSubcommandHelpAndExit() Add a ShowSubcommandHelpAndExit() Apr 23, 2022
@meatballhat meatballhat added the kind/feature describes a code enhancement / feature request label Apr 23, 2022
@meatballhat
Copy link
Member

Actually closed via #1183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/feature describes a code enhancement / feature request status/triage maintainers still need to look into this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants