-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
45 lines (39 loc) · 804 Bytes
/
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 main
import (
"errors"
"flag"
"fmt"
"os"
"strings"
)
type contexts []string
var contextsFlag contexts
func (c *contexts) String() string {
return fmt.Sprint(*c)
}
func (c *contexts) Set(val string) error {
if len(*c) > 0 {
return errors.New("cannot set contexts multiple times")
}
args := strings.Split(val, ",")
for _, item := range args {
*c = append(*c, item)
}
return nil
}
func getCliFlags() []string {
helpusage := `Usage:
mkubectx [-contexts|-c ctx1,ctx2,...] command [args...]
contexts arguments can be passed as regular expression`
flag.Usage = func() {
fmt.Fprint(os.Stderr, helpusage)
}
flag.Var(&contextsFlag, "contexts", "")
flag.Var(&contextsFlag, "c", "")
flag.Parse()
if flag.NArg() == 0 {
flag.Usage()
os.Exit(2)
}
return flag.Args()
}