-
Notifications
You must be signed in to change notification settings - Fork 2
/
help.go
257 lines (243 loc) · 7.81 KB
/
help.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package main
import (
"fmt"
"github.com/cloudfoundry/cli/plugin"
)
var (
subcommands = []plugin.Command{
{
Name: getAuthInfoCommand,
HelpText: "Authenticate with Object Storage and save credentials",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + getAuthInfoCommand +
" service_name [--url] [-x]",
Options: map[string]string{
"url": "Display auth url in quiet mode",
"x": "Display x-auth token in quiet mode",
},
},
},
{
Name: showContainersCommand,
HelpText: "Show all containers in an Object Storage instance",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + showContainersCommand +
" service_name",
Options: map[string]string{},
},
},
{
Name: containerInfoCommand,
HelpText: "Show a given container's information",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + containerInfoCommand +
" service_name container_name",
Options: map[string]string{},
},
},
{
Name: makeContainerCommand,
HelpText: "Create a new container in an Object Storage instance",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + makeContainerCommand +
" service_name container_name [headers...] [-gr] [-rm-gr]",
Options: map[string]string{
"gr": "Short name for global read header",
"rm-gr": "Short name for remove read restrictions header",
},
},
},
{
Name: updateContainerCommand,
HelpText: "Update a container's metadata",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + updateContainerCommand +
" service_name container_name headers... [-gr] [-rm-gr]",
Options: map[string]string{
"gr": "Short name for global read header",
"rm-gr": "Short name for remove read restrictions header",
},
},
},
{
Name: renameContainerCommand,
HelpText: "Rename a container",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + renameContainerCommand +
" service_name container_name new_container_name",
Options: map[string]string{},
},
},
{
Name: deleteContainerCommand,
HelpText: "Remove a container from an Object Storage instance",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + deleteContainerCommand +
" service_name container_name [-f]",
Options: map[string]string{
"f": "Force delete even if not empty",
},
},
},
{
Name: showObjectsCommand,
HelpText: "Show all objects in a container",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + showObjectsCommand +
" service_name container_name",
Options: map[string]string{},
},
},
{
Name: objectInfoCommand,
HelpText: "Show a given object's information",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + objectInfoCommand +
" service_name container_name object_name",
Options: map[string]string{},
},
},
{
Name: putObjectCommand,
HelpText: "Upload a file as an object to Object Storage",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + putObjectCommand +
" service_name container_name path_to_local_file [-n object_name]",
Options: map[string]string{},
},
},
{
Name: getObjectCommand,
HelpText: "Download an object from Object Storage",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + getObjectCommand +
" service_name container_name object_name path_to_dl_location",
Options: map[string]string{},
},
},
{
Name: renameObjectCommand,
HelpText: "Rename an object",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + renameObjectCommand +
" service_name container_name object_name new_object_name",
Options: map[string]string{},
},
},
{
Name: copyObjectCommand,
HelpText: "Copy an object to another container",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + copyObjectCommand +
" service_name container_name object_name new_container_name",
Options: map[string]string{},
},
},
{
Name: deleteObjectCommand,
HelpText: "Remove an object from a container",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + deleteObjectCommand +
" service_name container_name object_name [-l]",
Options: map[string]string{
"l": "Delete all files associated with large object manifest object_name",
},
},
},
{
Name: makeDLOCommand,
HelpText: "Create a Dynamic Large Object in Object Storage",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + makeDLOCommand +
" service_name dlo_container dlo_name [-c object_container] [-p dlo_prefix]",
Options: map[string]string{
"c": "Destination container for DLO segments (defaults to dlo_container)",
"p": "Prefix to be used for DLO segments (default to dlo_name)",
},
},
},
{
Name: makeSLOCommand,
HelpText: "Create a Static Large Object in Object Storage",
UsageDetails: plugin.Usage{
Usage: "cf " + namespace + " " + makeSLOCommand +
" service_name slo_container slo_name source_file [-m] [-o output_file] [-s chunk_size] [-j num_threads]",
Options: map[string]string{
"m": "Only upload missing chunks",
"o": "Destination for log data, if desired",
"s": "Chunk size, in bytes (defaults to create 1GB chunks)",
"j": "Maximum number of uploader threads (defaults to the available number of CPUs)",
},
},
},
}
subcommandMap = map[string]plugin.Command{
getAuthInfoCommand: subcommands[0],
showContainersCommand: subcommands[1],
containerInfoCommand: subcommands[2],
makeContainerCommand: subcommands[3],
updateContainerCommand: subcommands[4],
renameContainerCommand: subcommands[5],
deleteContainerCommand: subcommands[6],
showObjectsCommand: subcommands[7],
objectInfoCommand: subcommands[8],
putObjectCommand: subcommands[9],
getObjectCommand: subcommands[10],
renameObjectCommand: subcommands[11],
copyObjectCommand: subcommands[12],
deleteObjectCommand: subcommands[13],
makeDLOCommand: subcommands[14],
makeSLOCommand: subcommands[15],
}
)
// toString creates a help message from a given plugin.Command
func toString(s plugin.Command) string {
help := ""
help += fmt.Sprintf("NAME:\n\t%s - %s\n\nUSAGE:\n\t%s\n", s.Name, s.HelpText, s.UsageDetails.Usage)
if len(s.UsageDetails.Options) > 0 {
help += fmt.Sprintf("\nOPTIONS:\n")
for k, v := range s.UsageDetails.Options {
help += fmt.Sprintf("\t-%s\t\t%v\n", k, v)
}
}
return help
}
// getSubcommandHelp returns the help info for a given subcommand
func getSubcommandHelp(name string) (string, error) {
subcommand, found := subcommandMap[name]
if !found {
return "", fmt.Errorf("%s is not a valid subcommand", name)
}
return toString(subcommand), nil
}
// help prints help info for a given subcommand
func (c *ObjectStoragePlugin) help(args []string) error {
if len(args) < 3 {
help := "Please provide a valid subcommand\n" +
"Available subcommands:\n" +
" " + getAuthInfoCommand + "\n" +
" " + showContainersCommand + "\n" +
" " + containerInfoCommand + "\n" +
" " + makeContainerCommand + "\n" +
" " + updateContainerCommand + "\n" +
" " + renameContainerCommand + "\n" +
" " + deleteContainerCommand + "\n" +
" " + showObjectsCommand + "\n" +
" " + objectInfoCommand + "\n" +
" " + putObjectCommand + "\n" +
" " + getObjectCommand + "\n" +
" " + renameObjectCommand + "\n" +
" " + copyObjectCommand + "\n" +
" " + deleteObjectCommand + "\n" +
" " + makeDLOCommand + "\n" +
" " + makeSLOCommand + "\n"
fmt.Print(help)
return nil
}
help, err := getSubcommandHelp(args[2])
if err != nil {
return err
}
fmt.Print(help)
return nil
}