-
Notifications
You must be signed in to change notification settings - Fork 12
/
flags.go
58 lines (51 loc) · 1.59 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
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"
)
type flags struct {
env string
configFile string
configPath string
configDir string
marathonHost string
marathonCurlOpts string
marathonForce bool
skipPrompt bool
verbose bool
}
func (f *flags) parse() (err error) {
// Parse flags
flag.StringVar(&f.env, "e", "", "Environment (e.g. \"prod\")")
flag.StringVar(&f.configFile, "f", "deploy.yaml", "Config File")
flag.StringVar(&f.marathonHost, "marathon.host", "", "Marathon Host (e.g. \"www.example.com\"")
flag.StringVar(&f.marathonCurlOpts, "marathon.curlopts", "", "Marathon cURL options (e.g. '-H \"OauthEmail: no-reply@cloudflare.com\"'). Note: only -H is currently supported.")
flag.BoolVar(&f.marathonForce, "marathon.force", false, "Add the ?force=true to the Marathon request")
flag.BoolVar(&f.skipPrompt, "y", false, "Skip confirmation prompt")
flag.BoolVar(&f.verbose, "v", false, "Verbose mode e.g. dump Marathon config")
flag.Parse()
// Validate flags
if f.env == "" || f.configFile == "" {
flag.Usage()
os.Exit(1)
}
f.configPath, err = filepath.Abs(f.configFile)
if err != nil {
return fmt.Errorf("Error parsing config file path: %s", err)
}
_, err = os.Stat(f.configPath)
if err != nil {
return fmt.Errorf("Invalid config file path '%s': %s", f.configFile, err)
}
f.configDir = filepath.Dir(f.configPath)
if f.marathonHost != "" && strings.Contains(f.marathonHost, "/") {
return fmt.Errorf(
"Marathon hostname cannot contain forward slash. Found: %s",
f.marathonHost,
)
}
return
}