kong icon indicating copy to clipboard operation
kong copied to clipboard

Help() Interface on flags seemingly unused?

Open alex-broad opened this issue 1 year ago • 5 comments

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 :(

alex-broad avatar May 07 '24 14:05 alex-broad

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.

alecthomas avatar May 07 '24 20:05 alecthomas

Thanks! Just to be clear, this is example help code in your repo :blush:

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

alex-broad avatar May 08 '24 11:05 alex-broad

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

alecthomas avatar May 08 '24 23:05 alecthomas

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 :)

alex-broad avatar May 09 '24 12:05 alex-broad

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

mkadirtan avatar May 17 '24 13:05 mkadirtan