diff options
| author | Patrick Spek <p.spek@tyil.nl> | 2024-11-28 14:10:02 +0100 |
|---|---|---|
| committer | Patrick Spek <p.spek@tyil.nl> | 2024-11-28 14:10:02 +0100 |
| commit | f63b54d9a316e14b961be1ac20c5039040b3964d (patch) | |
| tree | 23602957ccdff0b012749434820888bfc2b0c0e0 | |
| download | flags_list-f63b54d9a316e14b961be1ac20c5039040b3964d.tar.gz flags_list-f63b54d9a316e14b961be1ac20c5039040b3964d.tar.bz2 | |
| -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 |
