-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags.go
More file actions
40 lines (38 loc) · 1.12 KB
/
flags.go
File metadata and controls
40 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"flag"
"fmt"
"io"
"path/filepath"
"strings"
)
// flags parses command line flags
func flags(fs *flag.FlagSet, args []string, errOut io.Writer) (goMod, coverProfile, path string, err error) {
fs.Usage = func() {
fmt.Fprintf(fs.Output(), "%s usage:\n\n", filepath.Base(fs.Name()))
fs.PrintDefaults()
fmt.Fprintln(fs.Output())
}
fs.StringVar(&goMod, "gomod", "", "path to the root go.mod file")
fs.StringVar(&coverProfile, "coverprofile", "", "path to Go test coverage profile file")
fs.StringVar(&path, "path", "", "path where HTML files will be written")
if err := fs.Parse(args); err != nil {
return "", "", "", err
}
if goMod == "" {
fs.Usage()
return "", "", "", fmt.Errorf("no value specified for -gomod")
}
if coverProfile == "" {
fs.Usage()
return "", "", "", fmt.Errorf("no value specified for -coverprofile")
}
if path == "" {
fs.Usage()
return "", "", "", fmt.Errorf("no value specified for -path")
}
if len(fs.Args()) > 0 {
fmt.Fprintf(errOut, "ignored arguments: %s\n", strings.Join(fs.Args(), ", "))
}
return goMod, coverProfile, path, nil
}