-
Notifications
You must be signed in to change notification settings - Fork 26
/
root.go
95 lines (83 loc) · 2.46 KB
/
root.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
94
95
/*
Copyright (C) CESS. All rights reserved.
Copyright (C) Cumulus Encrypted Storage System. All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/
package console
import (
"fmt"
"os"
"github.com/CESSProject/cess-bucket/configs"
"github.com/spf13/cobra"
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: configs.Name,
Short: configs.Description,
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
rootCmd.CompletionOptions.HiddenDefaultCmd = true
err := rootCmd.Execute()
if err != nil {
fmt.Printf("\x1b[%dm[err]\x1b[0m %v\n", 41, err)
os.Exit(1)
}
}
// init
func init() {
rootCmd.AddCommand(
Command_Version(),
Command_State(),
Command_Run(),
Command_Withdraw(),
)
rootCmd.PersistentFlags().StringP("config", "c", "", "custom configuration file")
rootCmd.PersistentFlags().StringSliceP("rpc", "", nil, "rpc endpoint list")
rootCmd.PersistentFlags().StringP("ws", "", "", "workspace")
rootCmd.PersistentFlags().StringP("earnings", "", "", "earnings account")
rootCmd.PersistentFlags().IntP("port", "", 0, "listening port")
rootCmd.PersistentFlags().Uint64P("space", "", 0, "maximum space used (GiB)")
rootCmd.PersistentFlags().StringSliceP("boot", "", nil, "bootstap node list")
rootCmd.PersistentFlags().StringP("mnemonic", "m", "", "staking account mnemonic")
}
func Command_Version() *cobra.Command {
cc := &cobra.Command{
Use: "version",
Short: "Print version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(configs.Name + " " + configs.Version)
os.Exit(0)
},
DisableFlagsInUseLine: true,
}
return cc
}
func Command_State() *cobra.Command {
cc := &cobra.Command{
Use: "stat",
Short: "Query storage miner information",
Run: Command_State_Runfunc,
DisableFlagsInUseLine: true,
}
return cc
}
func Command_Run() *cobra.Command {
cc := &cobra.Command{
Use: "run",
Short: "Automatically register and run",
Run: runCmd,
DisableFlagsInUseLine: true,
}
return cc
}
func Command_Withdraw() *cobra.Command {
cc := &cobra.Command{
Use: "withdraw",
Short: "withdraw staking",
Run: Command_Withdraw_Runfunc,
DisableFlagsInUseLine: true,
}
return cc
}