Skip to content

Commit

Permalink
Bugfix: read configuration from environment correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
moio committed Mar 31, 2018
1 parent 07f1561 commit 20cb1c2
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ func init() {

// initConfig reads in config file and ENV variables if set.
func initConfig() {
// first, try from the commandline flag
// first, try via environment variable
ev := os.Getenv("MINIMA_CONFIG")
if ev != "" {
cfgString = ev
fmt.Println("Using configuration from $MINIMA_CONFIG")
return
}

// second, try from the commandline flag
if cfgFile != "" {
bytes, err := ioutil.ReadFile(cfgFile)
if err != nil {
Expand All @@ -47,20 +55,5 @@ func initConfig() {
return
}

// second, try via environment variable
ev := os.Getenv("MINIMA_CONFIG")
if ev != "" {
cfgString = ev
fmt.Println("Using configuration from $MINIMA_CONFIG")
return
}

// third, try with minima.yaml
bytes, err := ioutil.ReadFile("minima.yaml")
if err != nil {
log.Fatal(err)
}
cfgString = string(bytes)
fmt.Println("Using config file:", cfgFile)
return
}

0 comments on commit 20cb1c2

Please sign in to comment.