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

How to print command helpscreen #2008

Open
unera opened this issue Nov 20, 2024 · 3 comments
Open

How to print command helpscreen #2008

unera opened this issue Nov 20, 2024 · 3 comments
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this

Comments

@unera
Copy link

unera commented Nov 20, 2024

From time to time I want to show an error and then command helpscreen.

if args.Len() < 3 {
   fmt.Printf("You must choose at least 3 files!\")
   
  // --- the place 
   
   return cli.Exit("some text", 3)
}

How can I print the same screen as prints ./program help or ./program module help?

@unera unera added area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this labels Nov 20, 2024
@dearchap
Copy link
Contributor

@unera Depending on whether the command is a root command or is a subcommand you could use one of the following
ShowAppHelpAndExit or ShowSubcommandHelpAndExit

@unera
Copy link
Author

unera commented Nov 29, 2024

@dearchap
thanks, that works fine

But I have another question

I have an application that can have options at levels,

example:

foo [global opts] command [command opts] subcommand [subcommand opts]

But when I call ShowSubcommandHelpAndExit, it showes helpscreen that contains only description

foo command [command options]

Is there a way to show global options, too at the helpscreen?
Or at least note about they are exists and full list can be found at foo help screen?

@dearchap
Copy link
Contributor

dearchap commented Dec 2, 2024

@unera You can try using

ShowAppHelp(rootCommand)

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/question someone asking a question status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

2 participants