-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathargs.go
60 lines (49 loc) · 1.14 KB
/
args.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
package main
import (
"flag"
)
type Args struct {
SmokeTestPath string
ManifestPath string
AppName string
DeleteOldApps bool
}
func NewArgs(osArgs []string) Args {
args := Args{}
args.AppName = extractAppName(osArgs)
// Only use FlagSet so that we can pass string slice to Parse
f := flag.NewFlagSet("blue-green-deploy", flag.ExitOnError)
f.StringVar(&args.SmokeTestPath, "smoke-test", "", "")
f.StringVar(&args.ManifestPath, "f", "", "")
f.BoolVar(&args.DeleteOldApps, "delete-old-apps", false, "")
f.Parse(extractBgdArgs(osArgs))
return args
}
func indexOfAppName(osArgs []string) int {
index := 0
for i, arg := range osArgs {
if arg == "blue-green-deploy" || arg == "bgd" {
index = i + 1
break
}
}
if len(osArgs) > index {
return index
}
return -1
}
func extractAppName(osArgs []string) string {
// Assume an app name will be passed - issue #27
index := indexOfAppName(osArgs)
if index >= 0 {
return osArgs[index]
}
return ""
}
func extractBgdArgs(osArgs []string) []string {
index := indexOfAppName(osArgs)
if index >= 0 && len(osArgs) > index+1 {
return osArgs[index+1:]
}
return []string{}
}