cobra
cobra copied to clipboard
Is it possible to handle -h and --help differently?
Many programs show a short help message with -h and a detailed one with --help. Currently cobra handles both options in the same way. Is it possible to change this somehow with custom help messages?
Interesting question. You may be able to figure out which form of the flag was used on the command line in your custom function.
My current simple workaround is to catch -h before cobra takes over:
[..]
rootCmd.SetUsageTemplate(strings.TrimSpace(usage) + "\n")
if slices.Contains(os.Args, "-h") {
fmt.Println(shortusage)
os.Exit(0)
}
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}