Update help example to use vars (#429)

This commit is contained in:
Alex Broad
2024-05-27 12:02:24 +01:00
committed by GitHub
parent 2ab5733f11
commit 38e5c6198e
+7 -4
View File
@@ -7,14 +7,16 @@ import (
) )
var cli struct { var cli struct {
Flag flagWithHelp `help:"Regular flag help"` Flag flagWithHelp `help:"${flag_help}"`
Echo commandWithHelp `cmd:"" help:"Regular command help"` Echo commandWithHelp `cmd:"" help:"Regular command help"`
} }
type flagWithHelp bool type flagWithHelp bool
func (f *flagWithHelp) Help() string { // See https://github.com/alecthomas/kong?tab=readme-ov-file#variable-interpolation
return "🏁 additional flag help" var vars = kong.Vars{
"flag_help": "Extended flag help that might be too long for directly " +
"including in the struct tag field",
} }
type commandWithHelp struct { type commandWithHelp struct {
@@ -41,7 +43,8 @@ func main() {
kong.ConfigureHelp(kong.HelpOptions{ kong.ConfigureHelp(kong.HelpOptions{
Compact: true, Compact: true,
Summary: false, Summary: false,
})) }),
vars)
switch ctx.Command() { switch ctx.Command() {
case "echo <msg>": case "echo <msg>":
fmt.Println(cli.Echo.Msg) fmt.Println(cli.Echo.Msg)