This repository has been archived by the owner on Jan 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
93 lines (77 loc) · 1.64 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"os"
"sort"
"strconv"
"time"
"github.com/apex/log"
apexcli "github.com/apex/log/handlers/cli"
"github.com/urfave/cli"
"github.com/uw-labs/mona/internal/cmd"
)
var (
version string
compiled string
compileTime int64
)
func init() {
compileTime, _ = strconv.ParseInt(compiled, 10, 64)
}
func main() {
app := cli.NewApp()
app.Usage = "A go monorepo management tool"
app.Authors = []cli.Author{{
Name: "David Bond",
Email: "[email protected]",
}, {
Name: "Michal Bock",
}}
app.Copyright = "2019 David Bond"
app.Version = version
app.Compiled = time.Unix(compileTime, 0)
app.Commands = []cli.Command{
cmd.Init(),
cmd.AddApp(),
cmd.Diff(),
cmd.Run(),
cmd.Build(),
cmd.Test(),
cmd.Lint(),
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "wd",
Hidden: true,
Usage: "Flag that contains the current working directory",
},
cli.BoolFlag{
Name: "fail-fast",
Usage: "If set, causes a command to terminate after encountering first error",
EnvVar: "MONA_FAIL_FAST",
},
cli.BoolFlag{
Name: "verbose",
Usage: "If set, enables verbose logging output",
EnvVar: "MONA_VERBOSE",
},
}
app.Before = func(ctx *cli.Context) error {
log.SetHandler(apexcli.Default)
if ctx.Bool("verbose") {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
log.Infof("%s v%s", app.Name, app.Version)
wd, err := os.Getwd()
if err != nil {
return err
}
return ctx.Set("wd", wd)
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
if err := app.Run(os.Args); err != nil {
log.Fatal(err.Error())
}
}