-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
129 lines (102 loc) · 2.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"log"
"os"
"runtime/pprof"
"time"
"github.com/MRtecno98/bucket/bucket"
"github.com/hashicorp/go-multierror"
"github.com/urfave/cli/v2"
_ "github.com/MRtecno98/bucket/bucket/platforms"
_ "github.com/MRtecno98/bucket/bucket/repositories"
c "github.com/MRtecno98/bucket/cli"
_ "github.com/mattn/go-sqlite3"
)
var profile bool
func main() {
log.SetPrefix("bucket: ")
log.SetFlags(0)
defer pprof.StopCPUProfile()
cli.VersionFlag = &cli.BoolFlag{
Name: "version",
Aliases: []string{"V"},
Usage: "print tool version",
}
(&cli.App{
Name: "bucket",
Usage: "manages spigot servers and plugins",
UseShortOptionHandling: true,
Suggest: true,
Version: "v1.0.0",
Authors: []*cli.Author{
{
Name: "MRtecno98",
Email: "[email protected]",
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "context",
Aliases: []string{"c"},
Usage: "selects `URL` as the working directory",
Value: ".",
DefaultText: "current directory",
},
// TODO: Add repositories argument
&cli.StringFlag{
Name: "config",
Aliases: []string{"f"},
Usage: "selects `FILE` as the configuration file",
Value: bucket.ConfigName,
},
&cli.BoolFlag{
Name: "parallel",
Aliases: []string{"j"},
Usage: "disables multithreaded processes",
Value: true,
Destination: &bucket.GlobalConfig.Multithread,
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"v"},
Usage: "enables debug mode",
Value: bucket.DEBUG,
Destination: &bucket.DEBUG,
},
&cli.BoolFlag{
Name: "cpuprofile",
Usage: "write a cpu profile",
Destination: &profile,
},
&cli.BoolFlag{
Name: "plain",
Usage: "disables ANSI formatted output",
EnvVars: []string{"bucket.plain"},
},
},
Before: func(ctx *cli.Context) error {
if profile {
log.Println("starting CPU profile")
f, err := os.Create(bucket.NewProfileFilename())
if err != nil {
return err
}
err = pprof.StartCPUProfile(f)
if err != nil {
return err
}
}
if ctx.Bool("plain") {
os.Setenv("bucket.plain", "true")
}
c.Time = time.Now()
return nil
},
ExitErrHandler: func(_ *cli.Context, err error) {
if err != nil {
c.GlobalError = multierror.Append(c.GlobalError, err)
}
},
Commands: c.Commands,
}).Run(os.Args)
}