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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help() Interface on flags seemingly unused? #426

Closed
alex-broad opened this issue May 7, 2024 · 5 comments 路 Fixed by #429
Closed

Help() Interface on flags seemingly unused? #426

alex-broad opened this issue May 7, 2024 · 5 comments 路 Fixed by #429

Comments

@alex-broad
Copy link
Contributor

In the shell example code you provide an example of defining a Help() function on a flag:

type flagWithHelp bool

func (f *flagWithHelp) Help() string {
	return "馃弫 additional flag help"
}

But this doesn't appear to be displayed at any point when running the code:

$ go run . --help
Usage: help <command> [flags]

An app demonstrating HelpProviders

Flags:
  -h, --help    Show context-sensitive help.
      --flag    Regular flag help

Commands:
  echo <msg>    Regular argument help

Run "help <command> --help" for more information on a command.

My use case is I have enough text for the help that I'd like to supply it through a Help() function instead of in the struct tag, but the function never seems to be used :(

@alecthomas
Copy link
Owner

That example is invalid, the HelpProvider interface explicitly only supports args/commands. I think the main reason it wasn't supported on flags is that it requires extra type definitions for flags of basic types, but other than that I don't think there's any reason why it shouldn't.

@alex-broad
Copy link
Contributor Author

Thanks! Just to be clear, this is example help code in your repo 馃槉

It would be good to support this as otherwise it's hard to have flags with long Help strings :(

@alecthomas
Copy link
Owner

A workaround is to put the longer help into variables with kong.Vars{}

@alex-broad
Copy link
Contributor Author

Ooh! From here? That solves my problem, thanks! If I get time I might submit a PR amending the Help example as that is what led me astray :)

@mkadirtan
Copy link

I encountered the same issue and the examples led me here, too :) I will solve it with kong.Vars{}

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

Successfully merging a pull request may close this issue.

3 participants