-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (50 loc) · 1.45 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
/*
Copyright © 2022 Li Weiming <[email protected]>
*/
package main
import (
"os"
"github.com/wymli/makex/cmd"
"github.com/wymli/makex/cmd/template"
"github.com/wymli/makex/code"
"github.com/wymli/makex/internal/config"
"github.com/wymli/makex/internal/parser"
log "github.com/sirupsen/logrus"
)
func main() {
// we don't process error here, just parse flags
_ = cmd.RootCmd.ParseFlags(os.Args[1:])
if v, err := cmd.RootCmd.Flags().GetBool("verbose"); err == nil {
if v {
log.SetLevel(log.TraceLevel)
}
}
if version, err := cmd.RootCmd.Flags().GetBool("version"); err == nil {
if version {
// skip register
log.Debug("skip register user cmds, only show version")
cmd.Execute()
return
}
}
c, err := config.ReadMakexConfig()
if err != nil {
log.Fatalf("failed to read makex config, err:%v", err)
}
makexfilename := c.Makexfile
log.Debugf("[config] use makexfile: %s", makexfilename)
// 2. read makexfile
makexfile, err := parser.ReadMakexfile(makexfilename)
if err != nil {
log.Fatal(err)
}
// 3. register internal code snippet template init
log.Debugf("[register] registering internal code commands to cobra")
code.RegisterCmds(config.CODE_DIR_PATH, template.ExportInitCmd())
// 4. register makexfile cmds to cobra cmds
log.Debugf("[register] registering makexfile commands to cobra")
makexfile.RegisterCmds(cmd.RootCmd)
// 5. run cobra cmds executor
log.Debugf("[execute] executing cobra")
cmd.Execute()
}