Add envprefix tag

This commit is contained in:
Dan
2021-10-22 11:28:58 +07:00
committed by Alec Thomas
parent 749d3f0752
commit 2770a34ce6
5 changed files with 53 additions and 0 deletions
+3
View File
@@ -97,6 +97,7 @@ func flattenedFields(v reflect.Value) (out []flattenedField, err error) {
}
// Accumulate prefixes.
subf.tag.Prefix = tag.Prefix + subf.tag.Prefix
subf.tag.EnvPrefix = tag.EnvPrefix + subf.tag.EnvPrefix
// Combine parent vars.
subf.tag.Vars = tag.Vars.CloneWith(subf.tag.Vars)
}
@@ -138,6 +139,8 @@ MAIN:
name = tag.Prefix + name
}
tag.Env = tag.EnvPrefix + tag.Env
// Nested structs are either commands or args, unless they implement the Mapper interface.
if field.value.Kind() == reflect.Struct && (tag.Cmd || tag.Arg) && k.registry.ForValue(fv) == nil {
typ := CommandNode