-
Notifications
You must be signed in to change notification settings - Fork 217
/
commands.go
162 lines (132 loc) · 4.36 KB
/
commands.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package filestore
import (
"github.com/spf13/cobra"
"github.com/spaceuptech/space-cloud/space-cli/cmd/utils"
)
// GenerateSubCommands is the list of commands the filestore module exposes
func GenerateSubCommands() []*cobra.Command {
var generaterule = &cobra.Command{
Use: "filestore-rule [path to config file]",
RunE: actionGenerateFilestoreRule,
Aliases: []string{"filestore-rules"},
Example: "space-cli generate filestore-rule config.yaml --project myproject --log-level info",
}
var generateconfig = &cobra.Command{
Use: "filestore-config [path to config file]",
RunE: actionGenerateFilestoreConfig,
Aliases: []string{"filestore-configs"},
Example: "space-cli generate filestore-config config.yaml --project myproject --log-level info",
}
return []*cobra.Command{generaterule, generateconfig}
}
// GetSubCommands is the list of commands the filestore module exposes
func GetSubCommands() []*cobra.Command {
var getFileStoreRules = &cobra.Command{
Use: "filestore-rules",
Aliases: []string{"filestore-rule"},
RunE: actionGetFileStoreRule,
ValidArgsFunction: fileStoreRulesAutoCompleteFun,
}
var getFileStoreConfigs = &cobra.Command{
Use: "filestore-configs",
Aliases: []string{"filestore-config"},
RunE: actionGetFileStoreConfig,
}
return []*cobra.Command{getFileStoreRules, getFileStoreConfigs}
}
// DeleteSubCommands is the list of commands the filestore module exposes
func DeleteSubCommands() []*cobra.Command {
var deleteFileStoreRules = &cobra.Command{
Use: "filestore-rules",
Aliases: []string{"filestore-rule"},
RunE: actionDeleteFileStoreRule,
ValidArgsFunction: fileStoreRulesAutoCompleteFun,
Example: "space-cli delete filestore-rules ruleID --project myproject",
}
var deleteFileStoreConfigs = &cobra.Command{
Use: "filestore-configs",
Aliases: []string{"filestore-config"},
RunE: actionDeleteFileStoreConfig,
Example: "space-cli delete filestore-configs --project myproject",
}
return []*cobra.Command{deleteFileStoreRules, deleteFileStoreConfigs}
}
func actionGetFileStoreConfig(cmd *cobra.Command, args []string) error {
// Get the project and url parameters
project, check := utils.GetProjectID()
if !check {
return utils.LogError("Project not specified in flag", nil)
}
commandName := "filestore-config"
params := map[string]string{}
obj, err := GetFileStoreConfig(project, commandName, params)
if err != nil {
return err
}
if err := utils.PrintYaml(obj); err != nil {
return err
}
return nil
}
func actionGetFileStoreRule(cmd *cobra.Command, args []string) error {
// Get the project and url parameters
project, check := utils.GetProjectID()
if !check {
return utils.LogError("Project not specified in flag", nil)
}
commandName := "filestore-rule"
params := map[string]string{}
if len(args) != 0 {
params["id"] = args[0]
}
objs, err := GetFileStoreRule(project, commandName, params)
if err != nil {
return err
}
if err := utils.PrintYaml(objs); err != nil {
return err
}
return nil
}
func actionGenerateFilestoreRule(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return utils.LogError("incorrect number of arguments. Use -h to check usage instructions", nil)
}
dbruleConfigFile := args[0]
dbrule, err := generateFilestoreRule()
if err != nil {
return err
}
return utils.AppendConfigToDisk(dbrule, dbruleConfigFile)
}
func actionGenerateFilestoreConfig(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return utils.LogError("incorrect number of arguments. Use -h to check usage instructions", nil)
}
dbruleConfigFile := args[0]
dbrule, err := generateFilestoreConfig()
if err != nil {
return err
}
return utils.AppendConfigToDisk(dbrule, dbruleConfigFile)
}
func actionDeleteFileStoreConfig(cmd *cobra.Command, args []string) error {
// Get the project
project, check := utils.GetProjectID()
if !check {
return utils.LogError("Project not specified in flag", nil)
}
return deleteFileStoreConfig(project)
}
func actionDeleteFileStoreRule(cmd *cobra.Command, args []string) error {
// Get the project and url parameters
project, check := utils.GetProjectID()
if !check {
return utils.LogError("Project not specified in flag", nil)
}
prefix := ""
if len(args) != 0 {
prefix = args[0]
}
return deleteFileStoreRule(project, prefix)
}