Skip to content

Commit

Permalink
Add ignore flag to ignore packages (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
schlund authored and aeneasr committed Jan 9, 2020
1 parent ff044a3 commit 974207e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $ go-acc $(glide novendor)
Flags:
--covermode string Which code coverage mode to use (default "atomic")
--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
Expand Down
16 changes: 15 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ $ go-acc . -- -short -v -failfast
fmt.Println("Flag -v has been deprecated, use `go acc -- -v` instead!")
}

ignores := flagx.MustGetStringSlice(cmd, "ignore")

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

var packages []string
Expand Down Expand Up @@ -68,7 +70,18 @@ $ go-acc . -- -short -v -failfast
// go: downloading ...
// go: extracting ...
if len(s) > 0 && !strings.HasPrefix(s, "go: ") {
add = append(add, s)
// Test if package name contains ignore string
ignore := false
for _, ignoreStr := range ignores {
if strings.Contains(s, ignoreStr) {
ignore = true
break
}
}

if !ignore {
add = append(add, s)
}
}
}

Expand Down Expand Up @@ -170,6 +183,7 @@ func init() {
RootCmd.Flags().BoolP("verbose", "v", false, "Does nothing, there for compatibility")
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")
}

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

0 comments on commit 974207e

Please sign in to comment.