go-arg
go-arg copied to clipboard
Description() doesn't work for sub commands
Description() defined for subcommands is not used for help text.
I think only root arg is considered.
parse.go line 232:
if dest, ok := dest.(Described); ok {
p.description = dest.Description()
}
Yes, it's true. It is a significant shortcoming of the API. Thank you for investigating it. I need to find time to develop an API that can support this.
Fixed in #156
I was looking at this, and the main issue seems to be that description exists on Parser, instead of on command.
Moving the field is fairly easy, but then we still need to populate to it somehow. This means we'd probably need to do it in cmdFromStruct, but I can't quite figure out how to get access to Description() there, as I have a name string, dest path, and t reflect.Type.
I can get to the method with meth, ok := t.MethodByName("Description") and if the struct you passed in has a Description on it we'll now have the method. The thing I can't figure out is how to then correctly do meth.Func.Call([]reflect.Value{reflect.ValueOf(...what goes here...)}).
If that can be made to work, then the output of the Description() can de assigned to cmd.description and it looks like all you then need is to change writeHelpForSubcommand to do
if p.cmd.description != "" {
fmt.Fprintln(w, p.cmd.description)
}
Epilogue can probably be made to work the same way, so those too would be per command instead of global on the parser.