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

fix: add cmd line argument for build tags #33

Merged
merged 2 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ 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

```
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