forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.go
59 lines (50 loc) · 927 Bytes
/
env.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 config
import (
"errors"
"os"
"strings"
"github.com/kballard/go-shellquote"
log "github.com/sirupsen/logrus"
)
var flags map[string]string
func init() {
err := loadFlags()
if err != nil {
log.Fatal(err)
}
}
func loadFlags() error {
flags = make(map[string]string)
opts, err := shellquote.Split(os.Getenv("ARGOCD_OPTS"))
if err != nil {
return err
}
var key string
for _, opt := range opts {
if strings.HasPrefix(opt, "--") {
if key != "" {
flags[key] = "true"
}
key = strings.TrimPrefix(opt, "--")
} else if key != "" {
flags[key] = opt
key = ""
} else {
return errors.New("ARGOCD_OPTS invalid at '" + opt + "'")
}
}
if key != "" {
flags[key] = "true"
}
return nil
}
func GetFlag(key, fallback string) string {
val, ok := flags[key]
if ok {
return val
}
return fallback
}
func GetBoolFlag(key string) bool {
return GetFlag(key, "false") == "true"
}