-
Notifications
You must be signed in to change notification settings - Fork 2
/
flags.go
145 lines (114 loc) · 2.85 KB
/
flags.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package varnamelen
import "strings"
// stringsValue is the value of a list-of-strings flag.
type stringsValue struct {
Values []string
}
// declarationsValue is the value of a list-of-declarations flag.
type declarationsValue struct {
Values []identDeclaration
}
// Set implements Value.
func (sv *stringsValue) Set(values string) error {
if strings.TrimSpace(values) == "" {
sv.Values = nil
return nil
}
parts := strings.Split(values, ",")
sv.Values = make([]string, len(parts))
for i, part := range parts {
sv.Values[i] = strings.TrimSpace(part)
}
return nil
}
// String implements Value.
func (sv *stringsValue) String() string {
return strings.Join(sv.Values, ",")
}
// contains returns true if sv contains s.
func (sv stringsValue) contains(s string) bool {
for _, v := range sv.Values {
if v == s {
return true
}
}
return false
}
// Set implements Value.
func (dv *declarationsValue) Set(values string) error {
if strings.TrimSpace(values) == "" {
dv.Values = nil
return nil
}
parts := strings.Split(values, ",")
dv.Values = make([]identDeclaration, len(parts))
for idx, part := range parts {
var err error
if dv.Values[idx], err = parseIdentDeclaration(strings.TrimSpace(part)); err != nil {
return err
}
}
return nil
}
// String implements Value.
func (dv *declarationsValue) String() string {
parts := make([]string, len(dv.Values))
for idx, val := range dv.Values {
parts[idx] = val.name + " " + val.typ
}
return strings.Join(parts, ",")
}
// matchVariable returns true if v matches any of the declarations in dv.
func (dv declarationsValue) matchVariable(v variable) bool {
for _, decl := range dv.Values {
if v.match(decl) {
return true
}
}
return false
}
// matchVariable returns true if c matches any of the declarations in dv.
func (dv declarationsValue) matchConstant(c constant) bool {
for _, decl := range dv.Values {
if c.match(decl) {
return true
}
}
return false
}
// matchParameter returns true if p matches any of the declarations in dv.
func (dv declarationsValue) matchParameter(p parameter) bool {
for _, decl := range dv.Values {
if p.match(decl) {
return true
}
}
return false
}
// matchParameter returns true if r matches any of the declarations in dv.
func (dv declarationsValue) matchNamedReturn(r namedReturn) bool {
for _, decl := range dv.Values {
if r.match(decl) {
return true
}
}
return false
}
// matchParameter returns true if r matches any of the declarations in dv.
func (dv declarationsValue) matchReceiver(r receiver) bool {
for _, decl := range dv.Values {
if r.match(decl) {
return true
}
}
return false
}
// matchParameter returns true if p matches any of the declarations in dv.
func (dv declarationsValue) matchTypeParameter(p typeParam) bool {
for _, decl := range dv.Values {
if p.match(decl) {
return true
}
}
return false
}