Allow Mappers to contribute Vars to interpolation.

See #218.
This commit is contained in:
Alec Thomas
2021-09-27 16:07:48 +10:00
parent dd18549686
commit 1d48b6f720
3 changed files with 39 additions and 0 deletions
+3
View File
@@ -183,6 +183,9 @@ func (k *Kong) interpolateValue(value *Value, vars Vars) (err error) {
if len(value.Tag.Vars) > 0 {
vars = vars.CloneWith(value.Tag.Vars)
}
if varsContributor, ok := value.Mapper.(VarsContributor); ok {
vars = vars.CloneWith(varsContributor.Vars(value))
}
if value.Default, err = interpolate(value.Default, vars, nil); err != nil {
return fmt.Errorf("default value for %s: %s", value.Summary(), err)
}