From 3b0fa9ff1ec49bd9271d04303ccdfa575348ae6d Mon Sep 17 00:00:00 2001 From: Arpad Ryszka Date: Thu, 15 Jan 2026 23:14:25 +0100 Subject: [PATCH] improve env and config example --- help.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/help.go b/help.go index 971d56c..de65747 100644 --- a/help.go +++ b/help.go @@ -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" }