...
1
2
3
4
5 package buildutil
6
7
8
9 import "fmt"
10
11 const TagsFlagDoc = "a list of `build tags` to consider satisfied during the build. " +
12 "For more information about build tags, see the description of " +
13 "build constraints in the documentation for the go/build package"
14
15
16
17
18
19
20
21
22
23
24
25 type TagsFlag []string
26
27 func (v *TagsFlag) Set(s string) error {
28 var err error
29 *v, err = splitQuotedFields(s)
30 if *v == nil {
31 *v = []string{}
32 }
33 return err
34 }
35
36 func (v *TagsFlag) Get() interface{} { return *v }
37
38 func splitQuotedFields(s string) ([]string, error) {
39
40
41 var f []string
42 for len(s) > 0 {
43 for len(s) > 0 && isSpaceByte(s[0]) {
44 s = s[1:]
45 }
46 if len(s) == 0 {
47 break
48 }
49
50 if s[0] == '"' || s[0] == '\'' {
51 quote := s[0]
52 s = s[1:]
53 i := 0
54 for i < len(s) && s[i] != quote {
55 i++
56 }
57 if i >= len(s) {
58 return nil, fmt.Errorf("unterminated %c string", quote)
59 }
60 f = append(f, s[:i])
61 s = s[i+1:]
62 continue
63 }
64 i := 0
65 for i < len(s) && !isSpaceByte(s[i]) {
66 i++
67 }
68 f = append(f, s[:i])
69 s = s[i:]
70 }
71 return f, nil
72 }
73
74 func (v *TagsFlag) String() string {
75 return "<tagsFlag>"
76 }
77
78 func isSpaceByte(c byte) bool {
79 return c == ' ' || c == '\t' || c == '\n' || c == '\r'
80 }
81
View as plain text