Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 485a71a

Browse files
authored
fix: add cmd line argument for build tags (#33)
Signed-off-by: Devrim Şahin <devrim.sahin@picussecurity.com>
1 parent 4c9d732 commit 485a71a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Flags:
2929
--ignore strings Will ignore packages that contains any of these strings
3030
-o, --output string Location for the output file (default "coverage.txt")
3131
-t, --toggle Help message for toggle
32+
--tags Build tags for go build and go test commands
3233
3334
```
3435

cmd/root.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ GO_TEST_BINARY="gotest"
6060
return err
6161
}
6262

63+
tagsArg := ""
64+
tags, err := cmd.Flags().GetStringSlice("tags")
65+
if err != nil {
66+
return err
67+
} else if len(tags) != 0 {
68+
tagsArg = "-tags="+strings.Join(tags, ",")
69+
}
70+
6371
payload := "mode: " + mode + "\n"
6472

6573
var packages []string
@@ -77,7 +85,7 @@ GO_TEST_BINARY="gotest"
7785

7886
if len(a) > 4 && a[len(a)-4:] == "/..." {
7987
var buf bytes.Buffer
80-
c := exec.Command("go", "list", a)
88+
c := exec.Command("go", "list", tagsArg, a)
8189
c.Stdout = &buf
8290
c.Stderr = &buf
8391
if err := c.Run(); err != nil {
@@ -133,6 +141,7 @@ GO_TEST_BINARY="gotest"
133141
"-covermode=" + mode,
134142
"-coverprofile=" + files[k],
135143
"-coverpkg=" + strings.Join(packages, ","),
144+
tagsArg,
136145
},
137146
passthrough...),
138147
pkg)
@@ -203,6 +212,7 @@ func init() {
203212
RootCmd.Flags().StringP("output", "o", "coverage.txt", "Location for the output file")
204213
RootCmd.Flags().String("covermode", "atomic", "Which code coverage mode to use")
205214
RootCmd.Flags().StringSlice("ignore", []string{}, "Will ignore packages that contains any of these strings")
215+
RootCmd.Flags().StringSlice("tags", []string{}, "Tags to include")
206216
}
207217

208218
// initConfig reads in config file and ENV variables if set.

0 commit comments

Comments
 (0)