summaryrefslogtreecommitdiff
path: root/flags.go
blob: e718370c30c5fc5369ba91ddb366274a2657440b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

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, ","))
}