-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
53 lines (41 loc) · 1.17 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
package main
import (
"fmt"
"os"
"github.com/Sirupsen/logrus"
"github.com/cloudway/platform/cmd/cwctl/cmds"
flag "github.com/cloudway/platform/pkg/mflag"
)
func main() {
stdout := os.Stdout
flag.Usage = func() {
flag.CommandLine.SetOutput(stdout)
fmt.Fprint(stdout, "Usage: cwctl [OPTIONS] COMMAND [arg...]\n cwctl [ --help ]\n")
help := "\nCommands:\n\n"
commands := cmds.CommandUsage
for _, cmd := range commands {
help += fmt.Sprintf(" %-10.10s%s\n", cmd.Name, cmd.Description)
}
fmt.Fprintf(stdout, "%s\n", help)
fmt.Fprint(stdout, "Options:\n")
flag.PrintDefaults()
fmt.Fprint(stdout, "\nRun 'cwctl COMMAND --help' for more information on a command.\n")
}
flgHelp := flag.Bool([]string{"h", "-help"}, false, "Print usage")
flgDebug := flag.Bool([]string{"D", "-debug"}, false, "Debugging mode")
flag.Parse()
if *flgHelp {
// if global flag --help is present, regardless of what other options
// and commands there are, just print the usage.
flag.Usage()
return
}
if *flgDebug {
logrus.SetLevel(logrus.DebugLevel)
}
c := cmds.Init()
if err := c.Run(flag.Args()...); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}