You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Notice that the "args" should be "arg1 arg2" but are not
Calling: prog sub arg1 arg2 -h
parameter cmd: sub
param args: [sub arg1 arg2 -h]
# Notice that the "args" should be "arg1 arg2" but are not
Calling: prog help sub arg1 arg2
parameter cmd: sub
param args: []
I can override the help function using:
cmd.SetHelpFunc(func(c *cobra.Command, args []string))
.Notice that the new help function I will define takes a command and its arguments as parameters, just like we have in many cobra functions.
I may choose to print a different help text based on what args the user has typed.
However, my help function does not get passed the correct args.
There are two situations where the help function is called:
--help/-h
flag (e.g.,prog sub arg1 -h
)help
command (e.g.,prog help sub arg1
)The below test shows that both cases are problematic (see program below).
Try it on playground: https://go.dev/play/p/UvaMTHq5Mqp
Test program
The text was updated successfully, but these errors were encountered: