-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcli.go
63 lines (52 loc) · 1.33 KB
/
cli.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
// Copyright (c) The EfficientGo Authors.
// Licensed under the Apache License 2.0.
package e2e
import "strings"
func EmptyFlags() map[string]string {
return map[string]string{}
}
func MergeFlags(inputs ...map[string]string) map[string]string {
output := MergeFlagsWithoutRemovingEmpty(inputs...)
for k, v := range output {
if v == "" {
delete(output, k)
}
}
return output
}
func MergeFlagsWithoutRemovingEmpty(inputs ...map[string]string) map[string]string {
output := map[string]string{}
for _, input := range inputs {
for name, value := range input {
output[name] = value
}
}
return output
}
func BuildArgs(flags map[string]string) []string {
args := make([]string, 0, len(flags))
for name, value := range flags {
if value != "" {
args = append(args, name+"="+value)
continue
}
args = append(args, name)
}
return args
}
// BuildKingpinArgs is like BuildArgs but with special handling of slice args.
// NOTE(bwplotka): flags with values as comma but not indented to be slice will cause issues.
func BuildKingpinArgs(flags map[string]string) []string {
args := make([]string, 0, len(flags))
for name, value := range flags {
if value != "" {
s := strings.Split(value, ",")
for _, ss := range s {
args = append(args, name+"="+ss)
}
continue
}
args = append(args, name)
}
return args
}