improve env and config example
This commit is contained in:
parent
514cd3375d
commit
3b0fa9ff1e
23
help.go
23
help.go
@ -694,6 +694,21 @@ func docFullSubcommands(cmd Cmd, conf Config, level int) []Entry {
|
|||||||
return e
|
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 {
|
func docEnv(cmd Cmd, level int) []Entry {
|
||||||
// env will not work if the app has a non-standard name:
|
// env will not work if the app has a non-standard name:
|
||||||
if !commandNameExpression.MatchString(cmd.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))
|
e = append(e, Indent(Title(level+2, "Example environment variable:"), 4, 0))
|
||||||
option := options[0]
|
option := options[0]
|
||||||
name := strcase.ToScreamingSnake(fmt.Sprintf("%s-%s", cmd.name, option.Name()))
|
name := strcase.ToScreamingSnake(fmt.Sprintf("%s-%s", cmd.name, option.Name()))
|
||||||
value := "42"
|
value := exampleValue(option)
|
||||||
if option.Type() == bind.Bool {
|
|
||||||
value = "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
e = append(e, Indent(CodeBlock(fmt.Sprintf("%s=%s", name, value)), 4, 0))
|
e = append(e, Indent(CodeBlock(fmt.Sprintf("%s=%s", name, value)), 4, 0))
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
@ -767,7 +778,7 @@ func docConfig(cmd Cmd, conf Config, level int) []Entry {
|
|||||||
|
|
||||||
option := options[0]
|
option := options[0]
|
||||||
name := option.Name()
|
name := option.Name()
|
||||||
value := "42"
|
value := exampleValue(option)
|
||||||
if option.Type() == bind.Bool {
|
if option.Type() == bind.Bool {
|
||||||
value = "true"
|
value = "true"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user