about summary refs log tree commit diff
path: root/internal/flag/flag.go
blob: 7c7d9773277ac60f921ad76880702db1bc9e5d49 (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
package flag

import (
	"fmt"
	"strings"
)

// A StringsValue is a command-line flag that interprets its argument
// as a space-separated list of strings.
type StringsValue []string

// Set implements the flag.Value interface by spliting the provided string at
// spaces.
func (v *StringsValue) Set(s string) error {
	if s == "" {
		*v = []string{}
		return nil
	}

	*v = strings.Fields(s)

	return nil
}

// Get implements the flag.Getter interface by returning the contents of this
// value.
func (v *StringsValue) Get() interface{} {
	return []string(*v)
}

// String returns a string
func (v *StringsValue) String() string {
	return fmt.Sprintf("%s", *v)
}