-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (60 loc) · 1.09 KB
/
main.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"log"
"os"
"github.com/skelouse/cover-pretty/go/cover"
"github.com/skelouse/cover-pretty/parse"
"github.com/urfave/cli/v3"
)
var (
htmlFlag = &cli.BoolFlag{
Name: "html",
}
funcFlag = &cli.BoolFlag{
Name: "func",
}
outFlag = &cli.StringFlag{
Name: "out",
Aliases: []string{"o"},
Usage: "path to output file",
}
)
func action(ctx *cli.Context) (err error) {
var in string
if ctx.Args().Len() > 0 {
in = ctx.Args().Get(0)
} else {
in, err = parse.Discover()
if err != nil {
return fmt.Errorf("finding `cover.out` failed with: %s", err)
}
}
out := ctx.String(outFlag.Name)
doHTML := ctx.IsSet(htmlFlag.Name)
doFunc := ctx.IsSet(funcFlag.Name)
// Default
if doHTML || !doHTML && !doFunc {
err = cover.HtmlOutput(in, out)
if err != nil {
return err
}
}
if doFunc {
err = cover.FuncOutput(in, out)
if err != nil {
return err
}
}
return nil
}
func main() {
app := &cli.App{
Flags: []cli.Flag{htmlFlag, funcFlag, outFlag},
Action: action,
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}