diff --git a/command.go b/command.go index c5b45545da7af9d0028c8f9b9c8cde00728ad5b9..e58b438a06846701ce08c3cf5a6357ed1700f46e 100644 --- a/command.go +++ b/command.go @@ -122,6 +122,21 @@ func (c *cmd[C]) initFlags(x reflect.Value, m map[string]string) { if m[tagLong] != "" { c.flagSet.String(m[tagLong], x.String(), m[tagDescription]) } + case reflect.Slice: + + if x.Type() == reflect.TypeOf(StringFlags{}) { + + if m[tagShort] != "" { + xx := x.Interface().(StringFlags) + c.flagSet.Var(&xx, m[tagShort], m[tagDescription]) + } + + if m[tagLong] != "" { + xx := x.Interface().(StringFlags) + c.flagSet.Var(&xx, m[tagLong], m[tagDescription]) + } + + } default: c.settings.errors = append(c.settings.errors, newUnsupportedFlagTypeError(x.Type())) @@ -163,7 +178,6 @@ func (c *cmd[C]) parseStruct(dta any) { } c.initFlags(x, m) } else if m[tagCommand] != "" { - //c.tagMapping["cmd"+m[tagCommand]] = v.Type().Field(i).Name c.initCommands(x, m, v.Type().Field(i).Name) } else if m[tagIgnore] != "" { diff --git a/hint.go b/hint.go new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/mapping.go b/mapping.go index 7531bb5bc7eeee14d6e5ec6f70230c8fd5549674..19a0b66771c6c7947fc10bb2dcc5dc980a2fa7bd 100644 --- a/mapping.go +++ b/mapping.go @@ -48,7 +48,18 @@ func (s *Settings[C]) assignValues(c cmd[C]) { pa := append(c.valuePath, k) p := strings.Join(pa, ".") - err := pathfinder.SetValue(&s.definitions, p, value) + q, err := pathfinder.GetValue(&s.definitions, p) + if err != nil { + s.errors = append(s.errors, err) + return + } + + if q == nil { + q = reflect.New(reflect.TypeOf(q).Elem()).Interface() + } + + err = pathfinder.SetValue(&s.definitions, p, value) + if err != nil { s.errors = append(s.errors, err) } diff --git a/type.go b/type.go new file mode 100644 index 0000000000000000000000000000000000000000..48172c48ba447139f3ba2514ebfaab704f6bc2ad --- /dev/null +++ b/type.go @@ -0,0 +1,30 @@ +package xflags + +import "strings" + +type StringFlags []string + +func (i *StringFlags) String() string { + return strings.Join(*i, ",") +} + +func (i *StringFlags) Set(value string) error { + *i = append(*i, value) + return nil +} + +type IntFlags []int + +func (i *IntFlags) String() string { + r := make([]string, len(*i)) + for k, v := range *i { + r[k] = string(v) + } + + return strings.Join(r, ",") +} + +func (i *IntFlags) Set(value int) error { + *i = append(*i, value) + return nil +}