3 // This logic was copied from stringsFlag from $GOROOT/src/cmd/go/build.go.
7 const TagsFlagDoc = "a list of `build tags` to consider satisfied during the build. " +
8 "For more information about build tags, see the description of " +
9 "build constraints in the documentation for the go/build package"
11 // TagsFlag is an implementation of the flag.Value and flag.Getter interfaces that parses
12 // a flag value in the same manner as go build's -tags flag and
13 // populates a []string slice.
15 // See $GOROOT/src/go/build/doc.go for description of build tags.
16 // See $GOROOT/src/cmd/go/doc.go for description of 'go build -tags' flag.
19 // flag.Var((*buildutil.TagsFlag)(&build.Default.BuildTags), "tags", buildutil.TagsFlagDoc)
20 type TagsFlag []string
22 func (v *TagsFlag) Set(s string) error {
24 *v, err = splitQuotedFields(s)
31 func (v *TagsFlag) Get() interface{} { return *v }
33 func splitQuotedFields(s string) ([]string, error) {
34 // Split fields allowing '' or "" around elements.
35 // Quotes further inside the string do not count.
38 for len(s) > 0 && isSpaceByte(s[0]) {
44 // Accepted quoted string. No unescaping inside.
45 if s[0] == '"' || s[0] == '\'' {
49 for i < len(s) && s[i] != quote {
53 return nil, fmt.Errorf("unterminated %c string", quote)
60 for i < len(s) && !isSpaceByte(s[i]) {
69 func (v *TagsFlag) String() string {
73 func isSpaceByte(c byte) bool {
74 return c == ' ' || c == '\t' || c == '\n' || c == '\r'