-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmd.go
116 lines (90 loc) · 3.15 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"os"
"github.com/spf13/cobra"
"github.com/G7DAO/safes/bindings/Safe"
"github.com/G7DAO/safes/bindings/SafeL2"
"github.com/G7DAO/safes/bindings/SafeProxy"
"github.com/G7DAO/safes/bindings/SafeProxyFactory"
)
var SAFES_VERSION string = "0.0.1"
func CreateRootCommand() *cobra.Command {
// rootCmd represents the base command when called without any subcommands
rootCmd := &cobra.Command{
Use: "game7",
Short: "game7: CLI to the Game7 protocol",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
completionCmd := CreateCompletionCommand(rootCmd)
versionCmd := CreateVersionCommand()
singletonCmd := Safe.CreateSafeCommand()
singletonCmd.Use = "singleton"
singletonL2Cmd := SafeL2.CreateSafeL2Command()
singletonL2Cmd.Use = "singleton-l2"
proxyCmd := SafeProxy.CreateSafeProxyCommand()
proxyCmd.Use = "proxy"
factoryCmd := SafeProxyFactory.CreateSafeProxyFactoryCommand()
factoryCmd.Use = "factory"
delegateCmd := CreateDelegateCmd()
rootCmd.AddCommand(completionCmd, versionCmd, singletonCmd, singletonL2Cmd, proxyCmd, factoryCmd, delegateCmd)
// By default, cobra Command objects write to stderr. We have to forcibly set them to output to
// stdout.
rootCmd.SetOut(os.Stdout)
return rootCmd
}
func CreateCompletionCommand(rootCmd *cobra.Command) *cobra.Command {
completionCmd := &cobra.Command{
Use: "completion",
Short: "Generate shell completion scripts for game7",
Long: `Generate shell completion scripts for game7.
The command for each shell will print a completion script to stdout. You can source this script to get
completions in your current shell session. You can add this script to the completion directory for your
shell to get completions for all future sessions.
For example, to activate bash completions in your current shell:
$ . <(game7 completion bash)
To add game7 completions for all bash sessions:
$ game7 completion bash > /etc/bash_completion.d/game7_completions`,
}
bashCompletionCmd := &cobra.Command{
Use: "bash",
Short: "bash completions for game7",
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenBashCompletion(cmd.OutOrStdout())
},
}
zshCompletionCmd := &cobra.Command{
Use: "zsh",
Short: "zsh completions for game7",
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenZshCompletion(cmd.OutOrStdout())
},
}
fishCompletionCmd := &cobra.Command{
Use: "fish",
Short: "fish completions for game7",
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenFishCompletion(cmd.OutOrStdout(), true)
},
}
powershellCompletionCmd := &cobra.Command{
Use: "powershell",
Short: "powershell completions for game7",
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenPowerShellCompletion(cmd.OutOrStdout())
},
}
completionCmd.AddCommand(bashCompletionCmd, zshCompletionCmd, fishCompletionCmd, powershellCompletionCmd)
return completionCmd
}
func CreateVersionCommand() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Print the version of game7 that you are currently using",
Run: func(cmd *cobra.Command, args []string) {
cmd.Println(SAFES_VERSION)
},
}
return versionCmd
}