-
Notifications
You must be signed in to change notification settings - Fork 22
/
flag.go
357 lines (317 loc) · 8.76 KB
/
flag.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package flag
import (
"github.com/aliyun/aliyun_assist_client/thirdparty/aliyun-cli/cli"
"github.com/aliyun/aliyun_assist_client/thirdparty/aliyun-cli/i18n"
)
const (
HelpFlagName = "help"
VerboseFlagName = "verbose"
VersionFlagName = "version"
ListFlagName = "list"
LocalFlagName = "local"
VerifyFlagName = "verify"
StatusFlagName = "status"
PluginFlagName = "plugin"
PluginIdFlagName = "pluginId"
PluginVersionFlagName = "pluginVersion"
ParamsFlagName = "params"
ParamsV2FlagName = "paramsV2"
UrlFlagName = "url"
SeparatorFlagName = "separator"
FileFlagName = "file"
ExecFlagName = "exec"
FetchTimeoutFlagName = "fetchTimeout"
ExecutionTimeoutFlagName = "timeout"
RemoveFlagName = "remove"
)
func AddFlags(fs *cli.FlagSet) {
fs.Add(NewHelpFlag())
fs.Add(NewVersionFlag())
fs.Add(NewLocalFlag())
fs.Add(NewPluginFlag())
fs.Add(NewPluginIdFlag())
fs.Add(NewPluginVersionFlag())
fs.Add(NewParamsFlag())
fs.Add(NewParamsV2Flag())
fs.Add(NewUrlFlag())
fs.Add(NewSeparatorFlag())
fs.Add(NewFileFlag())
fs.Add(NewVerboseFlag())
fs.Add(NewListFlag())
fs.Add(NewVerifyFlag())
fs.Add(NewStatusFlag())
fs.Add(NewExecFlag())
fs.Add(NewFetchTimeoutFlag())
fs.Add(NewExecutionTimeoutFlag())
fs.Add(NewRemoveFlag())
}
func VerboseFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(VerboseFlagName)
}
func ListFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(ListFlagName)
}
func LocalFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(LocalFlagName)
}
func VersionFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(VersionFlagName)
}
func VerifyFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(VerifyFlagName)
}
func StatusFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(StatusFlagName)
}
func PluginFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(PluginFlagName)
}
func PluginIdFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(PluginIdFlagName)
}
func PluginVersionFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(PluginVersionFlagName)
}
func ParamsFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(ParamsFlagName)
}
func ParamsV2Flag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(ParamsV2FlagName)
}
func UrlFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(UrlFlagName)
}
func SeparatorFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(SeparatorFlagName)
}
func FileFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(FileFlagName)
}
func ExecFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(ExecFlagName)
}
func FetchTimeoutFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(FetchTimeoutFlagName)
}
func ExecutionTimeoutFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(ExecutionTimeoutFlagName)
}
func RemoveFlag(fs *cli.FlagSet) *cli.Flag {
return fs.Get(RemoveFlagName)
}
func NewHelpFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: HelpFlagName,
Shorthand: 'h',
AssignedMode: cli.AssignedNone,
Persistent: true,
Short: i18n.T(
`--help, print this page`,
`--help, 打印此帮助页`,
),
}
}
func NewVerboseFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: VerboseFlagName,
Shorthand: 'V',
AssignedMode: cli.AssignedNone,
DefaultValue: "",
Persistent: true,
Short: i18n.T(
`--verbose, log more`,
`--verbose, 打印更多的日志`,
),
}
}
func NewVersionFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: VersionFlagName,
Shorthand: 'v',
AssignedMode: cli.AssignedNone,
DefaultValue: "",
Persistent: true,
Short: i18n.T(
`--version, print version`,
`--version, 打印版本号`,
),
}
}
func NewListFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: ListFlagName,
Shorthand: 'l',
AssignedMode: cli.AssignedNone,
DefaultValue: "",
Short: i18n.T(
`--list, show all plugins
--list --local, only show installed plugins`,
`--list, 列出所有插件
--list --local, 只列出本地已安装的插件`,
),
}
}
func NewLocalFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: LocalFlagName,
Shorthand: 'L',
AssignedMode: cli.AssignedNone,
DefaultValue: "",
Short: i18n.T(
` `,
` `,
),
}
}
func NewVerifyFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: VerifyFlagName,
Shorthand: 'f',
AssignedMode: cli.AssignedNone,
DefaultValue: "",
Short: i18n.T(
`--verify --url <> --params <>, verify plugin`,
`--verify --url <> --params <>, 验证插件`)}
}
func NewStatusFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: StatusFlagName,
Shorthand: 'S',
AssignedMode: cli.AssignedNone,
DefaultValue: "",
Short: i18n.T(
`--status, print all plugins status`,
`--status, 打印所有插件的状态`)}
}
func NewPluginFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: PluginFlagName,
Shorthand: 'P',
AssignedMode: cli.AssignedOnce,
DefaultValue: "",
Short: i18n.T(
`select plugin by name`,
`通过名称指定插件`)}
}
func NewPluginIdFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: PluginIdFlagName,
AssignedMode: cli.AssignedOnce,
DefaultValue: "",
Short: i18n.T(
"select plugin by id",
"通过插件id指定插件")}
}
func NewPluginVersionFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: PluginVersionFlagName,
Shorthand: 'n',
AssignedMode: cli.AssignedOnce,
DefaultValue: "",
Short: i18n.T(
"set plugin version",
"指定插件版本号")}
}
func NewParamsFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: ParamsFlagName,
Shorthand: 'p',
AssignedMode: cli.AssignedOnce,
Short: i18n.T(
"set params for plugin with separator, set separator by --separator",
"设置插件的运行参数,通过--separator设置参数的分隔符")}
}
func NewParamsV2Flag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: ParamsV2FlagName,
AssignedMode: cli.AssignedOnce,
Short: i18n.T(
"set params for plugin without separator",
"设置插件的运行参数,不使用分隔符分割")}
}
func NewUrlFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: UrlFlagName,
Shorthand: 'u',
AssignedMode: cli.AssignedOnce,
Short: i18n.T(
"set plugin's url",
"指定插件地址")}
}
func NewSeparatorFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: SeparatorFlagName,
Shorthand: 's',
AssignedMode: cli.AssignedOnce,
Short: i18n.T(
"set separator to split plugin's params, default is [,]",
"指定插件参数的分隔符,默认为逗号")}
}
func NewFileFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: FileFlagName,
Shorthand: 'F',
AssignedMode: cli.AssignedOnce,
Short: i18n.T(
"select plugin file",
"指定插件文件")}
}
func NewFetchTimeoutFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: FetchTimeoutFlagName,
AssignedMode: cli.AssignedOnce,
Short: i18n.T(
"Maximum time in seconds that you allow acs-plugin-manger to fetch the plugin. By default is 20 seconds. 0 means no time limit on fetching",
"允许获取插件过程消耗的最长时间,单位为秒。默认为20秒。设为0表示不限获取时间"),
}
}
func NewExecutionTimeoutFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: ExecutionTimeoutFlagName,
AssignedMode: cli.AssignedOnce,
Short: i18n.T(
"Maximum time in seconds that you allow the plugin to run. By default the value defined in plugin is used. 0 means no time limit on execution",
"允许插件运行的最长时间,单位为秒。默认使用插件包中定义的超时时间值。设为0表示不限运行时间"),
}
}
func NewExecFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: ExecFlagName,
Shorthand: 'e',
AssignedMode: cli.AssignedNone,
Short: i18n.T(
`--exec --plugin <> --params <>, execute plugin online
--exec --local --plugin <> --params <>, execute plugin from local
--exec --file <> --params <>, execute plugin from file`,
`--exec --plugin <> --params <>, 执行插件,优先从线上查找插件
--exec --local --plugin <> --params <>, 仅从本地查找执行插件
--exec --file <> --params <>, 从插件包文件执行插件`)}
}
func NewRemoveFlag() *cli.Flag {
return &cli.Flag{
Category: "caller",
Name: RemoveFlagName,
Shorthand: 'r',
AssignedMode: cli.AssignedNone,
Short: i18n.T(
`--remove --plugin <>, remove local plugin, will delete plugin's directories`,
`--remove --plugin <>, 移除本地插件,会删除掉该插件的目录文件`)}
}