-
Notifications
You must be signed in to change notification settings - Fork 13
/
flags.go
84 lines (72 loc) · 2.15 KB
/
flags.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
package main
import (
"fmt"
"strings"
"github.com/urfave/cli/v2"
)
const (
ClusterRole = "ClusterRole"
Role = "Role"
)
type EnumValue struct {
Enum []string
Default string
selected string
}
func (e *EnumValue) Set(value string) error {
for _, enum := range e.Enum {
if enum == value {
e.selected = value
return nil
}
}
return fmt.Errorf("allowed values are [%s]", strings.Join(e.Enum, ", "))
}
func (e *EnumValue) String() string {
if e.selected == "" {
return e.Default
}
return e.selected
}
func newTaskNameFlag(dest *string) *cli.StringFlag {
return &cli.StringFlag{Name: "task-name", EnvVars: envVars("TASK_NAME"), Required: true,
Usage: "Task Name",
Destination: dest,
}
}
func newNamespaceFlag(dest *string) *cli.StringFlag {
return &cli.StringFlag{Name: "namespace", Aliases: []string{"n"}, EnvVars: envVars("NAMESPACE"), Required: true,
Usage: "Namespace in which to find the resource.",
Destination: dest,
}
}
func newBlueprintNameFlag(dest *string) *cli.StringFlag {
return &cli.StringFlag{Name: "blueprint-name", EnvVars: envVars("BLUEPRINT_NAME"), Required: true,
Usage: "Blueprint Name",
Destination: dest,
}
}
func newScanRoleKindFlag() *cli.GenericFlag {
enum := &EnumValue{Enum: []string{ClusterRole, Role}, Default: ClusterRole}
return &cli.GenericFlag{Name: "scan-role-kind", EnvVars: envVars("SCAN_ROLE"),
Usage: "TODO",
Category: "Encoding",
DefaultText: fmt.Sprintf("%q [%s]", enum.Default, strings.Join(enum.Enum, ", ")),
Value: enum,
}
}
func newLogFormatFlag() *cli.GenericFlag {
enum := &EnumValue{Enum: []string{"console", "json"}, Default: "console"}
return &cli.GenericFlag{Name: "log-format", EnvVars: envVars("LOG_FORMAT"),
Usage: "sets the log format",
Category: "Encoding",
DefaultText: fmt.Sprintf("%q [%s]", enum.Default, strings.Join(enum.Enum, ", ")),
Value: enum,
}
}
func newSourceRootDirFlag(dest *string) *cli.StringFlag {
return &cli.StringFlag{Name: "source-root-dir", EnvVars: envVars("SOURCE_ROOT_DIR"),
Usage: "Directory path where to find the source files",
Destination: dest, Value: "/clustercode",
}
}