fix: update enum+default vars after interpolation

This doesn't recursively apply interpolation, as discussed in the issue,
but that's a much bigger change.

Fixes #337
This commit is contained in:
Alec Thomas
2024-11-03 14:28:27 +11:00
parent 1b9d57eec1
commit d0beaf7df3
2 changed files with 18 additions and 5 deletions
+13
View File
@@ -2314,3 +2314,16 @@ func TestIntEnum(t *testing.T) {
_, err = k.Parse([]string{"--enum=123"})
assert.EqualError(t, err, `--enum must be one of "1","2","3" but got "123"`)
}
func TestRecursiveVariableExpansion(t *testing.T) {
var cli struct {
Config string `type:"path" default:"${config_file}" help:"Default: ${default}"`
}
k := mustNew(t, &cli, kong.Vars{"config_file": "/etc/config"}, kong.Exit(func(int) {}))
w := &strings.Builder{}
k.Stderr = w
k.Stdout = w
_, err := k.Parse([]string{"--help"})
assert.NoError(t, err)
assert.Contains(t, w.String(), "Default: /etc/config")
}