-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflags.go
59 lines (49 loc) · 1.25 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
package main
import (
"flag"
"strings"
)
// Flags are command line flags.
type Flags struct {
allNamespaces bool
age bool
daemon bool
kind kinds
labelSelector string
namespace string
}
type kinds []string
func (k *kinds) String() string {
return strings.Join(*k, ", ")
}
func (k *kinds) Set(value string) error {
values := strings.Split(value, ",")
for i := range values {
values[i] = strings.TrimSpace(values[i])
}
*k = append(*k, values...)
return nil
}
// parseFlags parses and returns command line flags (options).
func parseFlags() Flags {
var f Flags
flag.BoolVar(&f.allNamespaces, "A", false, "count objects across all namespaces")
flag.BoolVar(&f.age, "a", false, "show also age of newest and oldest object")
flag.BoolVar(&f.daemon, "d", false, "run as daemon exposing prometheus metrics")
flag.Var(&f.kind, "k", "object kind or kinds (default is all supported)")
flag.StringVar(&f.labelSelector, "l", "", "label selector (e.g. env=prod)")
flag.StringVar(&f.namespace, "n", "", "namespace (default comes from kubeconfig)")
flag.Parse()
// Set default values.
if len(f.kind) == 0 {
f.kind = []string{
"deployment",
"pod",
"configmap",
"secret",
"ingress",
"service",
}
}
return f
}