Skip to content

Commit cc56482

Browse files
authored
Merge pull request #28 from go-tstr/go-cover-dir
Improve GOCOVERDIR
2 parents 2156ade + 6f392ff commit cc56482

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

dep/cmd/cmd.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,19 @@ func WithGoCode(modulePath, mainPkg string) Opt {
236236
}
237237
}
238238

239+
// WithGoCover calls WithGoCoverDir with the os.Getenv("GOCOVERDIR") value if it's set.
240+
// Otherwise it's a no-op.
241+
func WithGoCove() Opt {
242+
dir := os.Getenv("GOCOVERDIR")
243+
if dir == "" {
244+
return func(c *Cmd) error { return nil }
245+
}
246+
247+
return WithGoCoverDir(dir)
248+
}
249+
250+
// WithGoCoverDir creates the dir if it doesn't exist and
251+
// appends the GOCOVERDIR env variable into the commands env.
239252
func WithGoCoverDir(dir string) Opt {
240253
return func(c *Cmd) error {
241254
if err := os.MkdirAll(dir, 0o755); err != nil {

0 commit comments

Comments
 (0)