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 FailSubcommand, WriteUsageForSubcommand, WriteHelpForSubcommand #156

Merged
merged 3 commits into from
Sep 18, 2021

Conversation

alexflint
Copy link
Owner

Closes #134 #135 #139

This pr makes it possible to print usage and help text for explicit subcommands. It adds three new functions:

Parser.WriteUsageForSubcommand
Parser.WriteHelpForSubcommand
Parser.FailSubcommand

These behave like their non-subcommand cousins, except that they also take a subcommand name (or a sequence of subcommand names in the case of nested subcommands)

@codecov-commenter
Copy link

codecov-commenter commented May 9, 2021

Codecov Report

Merging #156 (f2f8764) into master (66cb696) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #156   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          650       679   +29     
=========================================
+ Hits           650       679   +29     
Impacted Files Coverage Δ
parse.go 100.00% <100.00%> (ø)
usage.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 66cb696...f2f8764. Read the comment docs.

@Keithcat1
Copy link

Thanks for this. Is there a way to enable printing help messages by default for nested subcommands? As I understand it, even with this pull request merged I would still have to call Parser.WriteHelpForSubcommand in each problematic subcommands code.

@Keithcat1
Copy link

Keithcat1 commented Jul 10, 2021

Why isn't this merged yet? It doesn't seem to be blocking on anything.

@chrisgoffinet
Copy link

@alexflint could we merge this?

@xvello
Copy link

xvello commented Oct 1, 2021

Hello @alexflint, thanks a lot for your work on this!

It does look like #139 is not completely fixed yet though: we are still printing p.description, which is obtained by calling Description() on the root command, not the subcommand selected by the user.

I am experimenting on this branch, but I'd love your input. Do you have any opinion on how that should be implemented?

@alexflint
Copy link
Owner Author

@xvello you are exactly right. I've reopened #139.

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.

Find a way to print help message for nested subcommands
5 participants