Skip to content

Commit

Permalink
fix: add cmd line argument for build tags (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: Devrim Şahin <[email protected]>
  • Loading branch information
kubuzetto authored Oct 8, 2021
1 parent 4c9d732 commit 485a71a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Flags:
--ignore strings Will ignore packages that contains any of these strings
-o, --output string Location for the output file (default "coverage.txt")
-t, --toggle Help message for toggle
--tags Build tags for go build and go test commands
```

Expand Down
12 changes: 11 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ GO_TEST_BINARY="gotest"
return err
}

tagsArg := ""
tags, err := cmd.Flags().GetStringSlice("tags")
if err != nil {
return err
} else if len(tags) != 0 {
tagsArg = "-tags="+strings.Join(tags, ",")
}

payload := "mode: " + mode + "\n"

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

if len(a) > 4 && a[len(a)-4:] == "/..." {
var buf bytes.Buffer
c := exec.Command("go", "list", a)
c := exec.Command("go", "list", tagsArg, a)
c.Stdout = &buf
c.Stderr = &buf
if err := c.Run(); err != nil {
Expand Down Expand Up @@ -133,6 +141,7 @@ GO_TEST_BINARY="gotest"
"-covermode=" + mode,
"-coverprofile=" + files[k],
"-coverpkg=" + strings.Join(packages, ","),
tagsArg,
},
passthrough...),
pkg)
Expand Down Expand Up @@ -203,6 +212,7 @@ func init() {
RootCmd.Flags().StringP("output", "o", "coverage.txt", "Location for the output file")
RootCmd.Flags().String("covermode", "atomic", "Which code coverage mode to use")
RootCmd.Flags().StringSlice("ignore", []string{}, "Will ignore packages that contains any of these strings")
RootCmd.Flags().StringSlice("tags", []string{}, "Tags to include")
}

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

0 comments on commit 485a71a

Please sign in to comment.