/
cmd.go
93 lines (82 loc) · 2.19 KB
/
cmd.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 (
"fmt"
"github.com/spf13/cobra"
)
var (
gui bool
)
func getRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "",
Run: func(cmd *cobra.Command, args []string) {
reloadCfg()
runApp()
},
}
rootCmd.Flags().BoolVarP(&gui, "gui", "g", false, "is gui?")
rootCmd.Flags().StringVarP(&cfgFilepath, "config", "c", "", "custom config file")
startCmd := &cobra.Command{
Use: "start",
Short: "start PHP Running Environment",
Run: func(cmd *cobra.Command, args []string) {
reloadCfg()
fmt.Println("启动环境...")
startEnv()
},
}
startCmd.Flags().StringVarP(&cfgFilepath, "config", "c", "", "custom config file")
rootCmd.AddCommand(startCmd)
var stopCmd = &cobra.Command{
Use: "stop",
Short: "Stop PHP Running Environment",
Run: func(cmd *cobra.Command, args []string) {
// 进程直接杀死就好,不需要用到配置的
fmt.Println("终止环境...")
stopEnv()
},
}
rootCmd.AddCommand(stopCmd)
var restartCmd = &cobra.Command{
Use: "restart",
Short: "restart PHP Running Environment",
Run: func(cmd *cobra.Command, args []string) {
reloadCfg()
fmt.Println("重启环境...")
stopEnv()
},
}
restartCmd.Flags().StringVarP(&cfgFilepath, "config", "c", "", "custom config file")
rootCmd.AddCommand(restartCmd)
var saveCmd = &cobra.Command{
Use: "save",
Short: "Save Current Config",
Run: func(cmd *cobra.Command, args []string) {
reloadCfg()
saveConfig()
},
}
saveCmd.Flags().StringVarP(&cfgFilepath, "config", "c", "", "custom config file")
rootCmd.AddCommand(saveCmd)
var exportCmd = &cobra.Command{
Use: "export",
Short: "Export Current Config",
Run: func(cmd *cobra.Command, args []string) {
reloadCfg()
exportNginx()
},
}
exportCmd.Flags().StringVarP(&cfgFilepath, "config", "c", "", "custom config file")
rootCmd.AddCommand(exportCmd)
var statusCmd = &cobra.Command{
Use: "status",
Short: "Check the status of NGINX and PHP",
Run: func(cmd *cobra.Command, args []string) {
// 进程直接查看就好,不需要调用配置信息的
nginxStatus, phpStatus := checkStatus()
showStatus(nginxStatus, phpStatus)
},
}
rootCmd.AddCommand(statusCmd)
return rootCmd
}