Add support for a mapper interface directly on fields.

If a field implements the MapperValue interface that interface will be
used.
This commit is contained in:
Alec Thomas
2018-06-29 12:33:50 +10:00
parent 0bc26a865d
commit b2cab08684
4 changed files with 72 additions and 13 deletions
+2 -2
View File
@@ -70,8 +70,8 @@ func buildNode(k *Kong, v reflect.Value, typ NodeType, seenFlags map[string]bool
name = strings.ToLower(dashedString(ft.Name))
}
// Nested structs are either commands or args.
if ft.Type.Kind() == reflect.Struct && (tag.Cmd || tag.Arg) {
// Nested structs are either commands or args, unless they implement the Mapper interface.
if ft.Type.Kind() == reflect.Struct && (tag.Cmd || tag.Arg) && k.registry.ForValue(fv) == nil {
typ := CommandNode
if tag.Arg {
typ = ArgumentNode