-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
95 lines (86 loc) · 2.06 KB
/
main.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
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
type appConfig struct {
configFile string
context string
namespace string
timeout time.Duration
variables variableMap
}
type variableMap map[string]string
func (v *variableMap) String() string {
return fmt.Sprint(*v)
}
func (v *variableMap) Set(value string) error {
pieces := strings.SplitN(value, "=", 2)
if len(pieces) != 2 {
return nil
}
(*v)[pieces[0]] = pieces[1]
return nil
}
func main() {
// check docker command
err := checkDockerCommand()
if err != nil {
ErrPrintln(ColorRed, "docker command not found, please install docker command line")
os.Exit(1)
}
config := &appConfig{
variables: make(variableMap),
}
flag.StringVar(&config.configFile, "kubeconfig", "", "Kube config file")
flag.StringVar(&config.context, "context", "", "Kube context")
flag.StringVar(&config.namespace, "namespace", "", "Kube namespace")
flag.DurationVar(&config.timeout, "timeout", 15*time.Minute, "timeout duration")
flag.Var(&config.variables, "variable", "override variables")
flag.Parse()
if config.configFile == "" {
config.configFile = filepath.Join(os.Getenv("HOME"), ".kube", "config")
}
args := flag.Args()
if len(args) == 0 {
printUsage()
}
switch args[0] {
case "version":
cmdVersion(args[1:], config)
case "up":
cmdUp(args[1:], config)
case "down":
cmdDown(args[1:], config)
case "down-services":
cmdDownServices(args[1:], config)
case "down-jobs":
cmdDownJobs(args[1:], config)
case "update":
cmdUpdate(args[1:], config)
case "wait":
cmdWait(args[1:], config)
case "log":
cmdLog(args[1:], config)
case "data":
cmdData(args[1:], config)
case "generate":
cmdGenerate(args[1:], config)
case "autoupdate":
cmdAutoUpdate(args[1:], config)
case "debug":
cmdDebug(args[1:], config)
default:
printUsage()
}
}
func printUsage() {
ErrPrintf(ColorWhite, "USAGE: %s <flag> [command] <folder>\n", os.Args[0])
ErrPrintf(ColorWhite, "Available commands: up, down, update, version, wait, log, data, generate\n")
flag.PrintDefaults()
os.Exit(2)
}