-
Notifications
You must be signed in to change notification settings - Fork 0
/
cobra.go
63 lines (55 loc) · 1.47 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
54
55
56
57
58
59
60
61
62
63
// description:
// @author renshiwei
// Date: 2022/10/6 14:36
package cmd
import (
"fmt"
"github.com/duktig666/ssv-keys-go/cmd/shares"
"github.com/duktig666/ssv-keys-go/cmd/version"
"github.com/duktig666/ssv-keys-go/common/global"
"github.com/duktig666/ssv-keys-go/common/initialize"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"os"
)
var (
cfgFile string
cliName = global.Config.Cli.Name
)
var rootCmd = &cobra.Command{
Use: cliName,
Short: cliName,
SilenceUsage: true,
Long: `https://github.com/duktig666/ssv-keys-go`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
tip()
return errors.New("requires at least one arg")
}
return nil
},
PreRun: func(cmd *cobra.Command, args []string) {
// init config file ...
initialize.InitServer(cfgFile)
},
Run: func(cmd *cobra.Command, args []string) {
tip()
},
}
func tip() {
usageStr := `Welcome to use ` + cliName + `:` + ` use ` + `-h` + ` see cli`
usageStr1 := `You can also refer to the related content of https://github.com/duktig666/ssv-keys-go 的相关内容`
fmt.Printf("%s\n", usageStr)
fmt.Printf("%s\n", usageStr1)
}
func init() {
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "config/config.yaml", "config file (default is config/config.yaml)")
rootCmd.AddCommand(version.StartCmd)
rootCmd.AddCommand(shares.StartCmd)
}
//Execute : apply commands
func Execute() {
if err := rootCmd.Execute(); err != nil {
os.Exit(-1)
}
}