github.com/argoproj/argo-cd@v1.8.7/util/config/env.go (about) 1 package config 2 3 import ( 4 "errors" 5 "os" 6 "strings" 7 8 "github.com/kballard/go-shellquote" 9 log "github.com/sirupsen/logrus" 10 ) 11 12 var flags map[string]string 13 14 func init() { 15 err := loadFlags() 16 if err != nil { 17 log.Fatal(err) 18 } 19 } 20 21 func loadFlags() error { 22 flags = make(map[string]string) 23 24 opts, err := shellquote.Split(os.Getenv("ARGOCD_OPTS")) 25 if err != nil { 26 return err 27 } 28 29 var key string 30 for _, opt := range opts { 31 if strings.HasPrefix(opt, "--") { 32 if key != "" { 33 flags[key] = "true" 34 } 35 key = strings.TrimPrefix(opt, "--") 36 } else if key != "" { 37 flags[key] = opt 38 key = "" 39 } else { 40 return errors.New("ARGOCD_OPTS invalid at '" + opt + "'") 41 } 42 } 43 if key != "" { 44 flags[key] = "true" 45 } 46 return nil 47 } 48 49 func GetFlag(key, fallback string) string { 50 val, ok := flags[key] 51 if ok { 52 return val 53 } 54 return fallback 55 } 56 57 func GetBoolFlag(key string) bool { 58 return GetFlag(key, "false") == "true" 59 }