cli icon indicating copy to clipboard operation
cli copied to clipboard

How to print command helpscreen

Open unera opened this issue 1 year ago • 3 comments

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 avatar Nov 20 '24 16:11 unera

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

dearchap avatar Nov 21 '24 11:11 dearchap

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

unera avatar Nov 29 '24 17:11 unera

@unera You can try using

ShowAppHelp(rootCommand)

dearchap avatar Dec 02 '24 17:12 dearchap