forked from miaokobot/miaospeed
-
Notifications
You must be signed in to change notification settings - Fork 9
/
cli.go
78 lines (63 loc) · 1.63 KB
/
cli.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
package main
import (
"flag"
"fmt"
"os"
"path"
"github.com/airportr/miaospeed/utils"
)
var cmdName = "miaospeed"
type SubCliType string
const (
SCTMisc SubCliType = "misc"
SCTServer SubCliType = "server"
SCTScriptTest SubCliType = "script"
)
func RunCli() {
subCmd := SubCliType("")
if len(os.Args) >= 2 {
subCmd = SubCliType(os.Args[1])
}
cmdName = path.Base(os.Args[0])
switch subCmd {
case SCTMisc:
RunCliMisc()
case SCTServer:
RunCliServer()
case SCTScriptTest:
RunCliScriptTest()
default:
RunCliDefault()
}
}
func RunCliDefault() {
sflag := flag.NewFlagSet(cmdName, flag.ExitOnError)
versionOnly := sflag.Bool("version", false, "display version and exit")
sflag.Parse(os.Args[1:])
if *versionOnly {
fmt.Println(utils.LOGO)
fmt.Printf("version: %s\n", utils.VERSION)
fmt.Printf("commit: %s\n", utils.COMMIT)
fmt.Printf("compilation time: %s\n", utils.COMPILATIONTIME)
os.Exit(0)
}
sflag.Usage()
fmt.Printf("\n")
fmt.Printf("Subcommands of %s:\n", cmdName)
fmt.Printf(" server\n")
fmt.Printf(" start the miaospeed backend as a server.\n")
fmt.Printf(" script\n")
fmt.Printf(" run a temporary script test to test the correctness of your script.\n")
fmt.Printf(" misc\n")
fmt.Printf(" other utility toolkit provided by miaospeed.\n")
fmt.Printf("Run this command to see the usage of the server option: \n")
fmt.Printf(" %s server -help\n", cmdName)
os.Exit(0)
}
func parseFlag(sflag *flag.FlagSet) {
verboseMode := sflag.Bool("verbose", false, "whether to print out systems log")
sflag.Parse(os.Args[2:])
if *verboseMode {
utils.VerboseLevel = utils.LTLog
}
}