forked from go-admin-team/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcobra.go
53 lines (48 loc) · 1.22 KB
/
cobra.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 cmd
import (
"errors"
"fmt"
"github.com/spf13/cobra"
"go-admin/cmd/api"
"go-admin/cmd/config"
"go-admin/cmd/migrate"
"go-admin/cmd/version"
"go-admin/global"
"go-admin/tools"
"os"
)
var rootCmd = &cobra.Command{
Use: "go-admin",
Short: "go-admin",
SilenceUsage: true,
Long: `go-admin`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
tip()
return errors.New(tools.Red("requires at least one arg"))
}
return nil
},
PersistentPreRunE: func(*cobra.Command, []string) error { return nil },
Run: func(cmd *cobra.Command, args []string) {
tip()
},
}
func tip() {
usageStr := `欢迎使用 `+ tools.Green( `go-admin ` +global.Version) + ` 可以使用 ` + tools.Red(`-h`) + ` 查看命令`
usageStr1 := `也可以参考 http://doc.zhangwj.com/go-admin-site/guide/ksks.html 里边的【启动】章节`
fmt.Printf("%s\n", usageStr)
fmt.Printf("%s\n", usageStr1)
}
func init() {
rootCmd.AddCommand(api.StartCmd)
rootCmd.AddCommand(migrate.StartCmd)
rootCmd.AddCommand(version.StartCmd)
rootCmd.AddCommand(config.StartCmd)
}
//Execute : apply commands
func Execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(-1)
}
}