diff options
| -rw-r--r-- | flags.go | 41 | ||||
| -rw-r--r-- | go.mod | 3 |
2 files changed, 44 insertions, 0 deletions
diff --git a/flags.go b/flags.go new file mode 100644 index 0000000..fd31c3c --- /dev/null +++ b/flags.go @@ -0,0 +1,41 @@ +package flags_list + +import ( + "fmt" + "strings" +) + +type MapVar map[string]string +type SliceVar []string + +func (this *MapVar) Set(value string) error { + if *this == nil { + *this = make(map[string]string) + } + + splits := strings.SplitN(value, "=", 2) + + (*this)[splits[0]] = splits[1] + + return nil +} + +func (this *MapVar) String() string { + slice := []string{} + + for key, value := range *this { + slice = append(slice, fmt.Sprintf("%s: %v,", key, value)) + } + + return fmt.Sprintf("{%s}", strings.Join(slice, ",")) +} + +func (this *SliceVar) Set(value string) error { + *this = append(*this, value) + + return nil +} + +func (this *SliceVar) String() string { + return fmt.Sprintf("[%s]", strings.Join(*this, ",")) +} @@ -0,0 +1,3 @@ +module git.tyil.nl/go/flags_list.git + +go 1.23.2 |
