From 485a71a545bd46895d2105bbe27572a239a9b663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Devrim=20=C5=9Eahin?= Date: Fri, 8 Oct 2021 19:54:46 +0300 Subject: [PATCH] fix: add cmd line argument for build tags (#33) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Devrim Şahin --- README.md | 1 + cmd/root.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d3870e..8ee25d7 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/cmd/root.go b/cmd/root.go index dc3c650..e09165d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 @@ -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 { @@ -133,6 +141,7 @@ GO_TEST_BINARY="gotest" "-covermode=" + mode, "-coverprofile=" + files[k], "-coverpkg=" + strings.Join(packages, ","), + tagsArg, }, passthrough...), pkg) @@ -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.