Automatically add envar to help.

See #57.
This commit is contained in:
Alec Thomas
2020-02-19 15:49:59 +11:00
parent b21bf1031a
commit 73ecfde9b2
4 changed files with 40 additions and 0 deletions
+13
View File
@@ -155,6 +155,19 @@ func (k *Kong) interpolateValue(value *Value, vars Vars) (err error) {
})
if value.Tag.Env != "" {
vars["env"] = value.Tag.Env
if !interpolationHasVar(value.Help, "env") {
suffix := "($" + value.Tag.Env + ")"
switch {
case strings.HasSuffix(value.Help, "."):
value.Help = value.Help[:len(value.Help)-1] + " " + suffix + "."
case value.Help == "":
value.Help += suffix
default:
value.Help += " " + suffix
}
}
}
if value.Help, err = interpolate(value.Help, vars); err != nil {
return fmt.Errorf("help for %s: %s", value.Summary(), err)