improve env and config example

This commit is contained in:
Arpad Ryszka 2026-01-15 23:14:25 +01:00
parent 514cd3375d
commit 3b0fa9ff1e

23
help.go
View File

@ -694,6 +694,21 @@ func docFullSubcommands(cmd Cmd, conf Config, level int) []Entry {
return e
}
func exampleValue(o bind.Field) string {
switch o.Type() {
case bind.Bool:
return "true"
case bind.String:
return o.Name()
case bind.Duration:
return "42s"
case bind.Time:
return "Thu Jan 15 23:11:53 CET 2026"
default:
return "42"
}
}
func docEnv(cmd Cmd, level int) []Entry {
// env will not work if the app has a non-standard name:
if !commandNameExpression.MatchString(cmd.name) {
@ -714,11 +729,7 @@ func docEnv(cmd Cmd, level int) []Entry {
e = append(e, Indent(Title(level+2, "Example environment variable:"), 4, 0))
option := options[0]
name := strcase.ToScreamingSnake(fmt.Sprintf("%s-%s", cmd.name, option.Name()))
value := "42"
if option.Type() == bind.Bool {
value = "true"
}
value := exampleValue(option)
e = append(e, Indent(CodeBlock(fmt.Sprintf("%s=%s", name, value)), 4, 0))
return e
}
@ -767,7 +778,7 @@ func docConfig(cmd Cmd, conf Config, level int) []Entry {
option := options[0]
name := option.Name()
value := "42"
value := exampleValue(option)
if option.Type() == bind.Bool {
value = "true"
}