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

Description() doesn't work for sub commands #139

Open
gpie3k opened this issue Feb 4, 2021 · 3 comments
Open

Description() doesn't work for sub commands #139

gpie3k opened this issue Feb 4, 2021 · 3 comments

Comments

@gpie3k
Copy link

gpie3k commented Feb 4, 2021

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()
}
@alexflint
Copy link
Owner

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.

@alexflint
Copy link
Owner

Fixed in #156

@daenney
Copy link
Contributor

daenney commented Oct 13, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants