summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2024-11-28 14:10:02 +0100
committerPatrick Spek <p.spek@tyil.nl>2024-11-28 14:10:02 +0100
commitf63b54d9a316e14b961be1ac20c5039040b3964d (patch)
tree23602957ccdff0b012749434820888bfc2b0c0e0
downloadflags_list-f63b54d9a316e14b961be1ac20c5039040b3964d.tar.gz
flags_list-f63b54d9a316e14b961be1ac20c5039040b3964d.tar.bz2
Initial commitHEADmaster
-rw-r--r--flags.go41
-rw-r--r--go.mod3
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, ","))
+}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..d44f15e
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module git.tyil.nl/go/flags_list.git
+
+go 1.23.2