github.com/kristofferahl/go-centry@v1.5.0/cmd/centry/environment.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 ) 8 9 func environmentOrDefault(key string, defaultValue string) string { 10 value := os.Getenv(key) 11 if value == "" { 12 value = defaultValue 13 } 14 return value 15 } 16 17 func overrideFromEnvironment(runtime *Runtime) { 18 context := runtime.context 19 cli := runtime.cli 20 envVersionName := fmt.Sprintf("%s_VERSION", strings.ToUpper(context.manifest.Config.Name)) 21 envVersion := os.Getenv(envVersionName) 22 if envVersion != "" { 23 runtime.events = append(runtime.events, fmt.Sprintf("setting the version from environment variable \"%s\"", envVersionName)) 24 cli.Version = envVersion 25 } 26 }