-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist_flag.go
More file actions
60 lines (53 loc) · 1.24 KB
/
list_flag.go
File metadata and controls
60 lines (53 loc) · 1.24 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package figtree
import (
"strings"
)
// ListFlag stores values in a list type configurable
type ListFlag struct {
values []string
}
func (tree *figTree) ListValues(name string) []string {
tree.mu.Lock()
defer tree.mu.Unlock()
name = tree.resolveName(name)
if _, exists := tree.figs[name]; !exists {
return []string{}
}
valueAny, ok := tree.values.Load(name)
if !ok {
return nil
}
_value, ok := valueAny.(*Value)
if !ok {
return nil
}
return _value.Flesh().ToList()
}
func (l *ListFlag) Values() []string {
if l.values == nil {
return []string{}
}
return l.values
}
// String returns the slice of strings using strings.Join
func (l *ListFlag) String() string {
if l.values == nil {
return ""
}
return strings.Join(l.values, ListSeparator)
}
// PolicyListAppend will apply ListFlag.Set to the list of values and not append to any existing values in the ListFlag
var PolicyListAppend bool = false
// Set unpacks a comma separated value argument and appends items to the list of []string
func (l *ListFlag) Set(value string) error {
if l.values == nil {
l.values = []string{}
}
items := strings.Split(value, ListSeparator)
if PolicyListAppend {
l.values = append(l.values, items...)
} else {
l.values = items
}
return nil
}