-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathcli.go
45 lines (36 loc) · 1.12 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
package cli
import (
"fmt"
"slices"
"strings"
)
type ForceCheckDisabledControllerKindsParser struct {
allowedControllerKinds []string
ParsedKinds []string
}
func (parser *ForceCheckDisabledControllerKindsParser) Parse(flagValue string) error {
if flagValue == "*" {
parser.ParsedKinds = parser.allowedControllerKinds
return nil
}
parser.ParsedKinds = []string{}
flagLoop:
for _, kind := range strings.Split(flagValue, ",") {
kind = strings.ToLower(kind)
for _, allowedControllerKind := range parser.allowedControllerKinds {
if kind == allowedControllerKind {
if !slices.Contains(parser.ParsedKinds, kind) {
parser.ParsedKinds = append(parser.ParsedKinds, kind)
}
continue flagLoop
}
}
return fmt.Errorf(`must be one of %s or * for all kinds`, strings.Join(parser.allowedControllerKinds, ", "))
}
return nil
}
func NewForceCheckDisabledControllerKindsParser() *ForceCheckDisabledControllerKindsParser {
parser := &ForceCheckDisabledControllerKindsParser{}
parser.allowedControllerKinds = []string{"deployment", "statefulset", "daemonset", "cronjob", "rollout"}
return parser
}