Skip to content

Commit

Permalink
fix: fixing bad config file name and reduced code
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Mavro committed Feb 28, 2018
1 parent 1f96f84 commit c63ec85
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"path/filepath"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -54,27 +53,18 @@ func initConfig() {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find current directory.
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
fmt.Println(err)
os.Exit(1)
}

// Search config in current directory with name ".msa-k8s-deployer" (without extension).
viper.AddConfigPath(dir)
viper.SetConfigName(".deployer.yaml")
// Search config in current directory
viper.AddConfigPath(".")
viper.SetConfigName(".deployer")
}

viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
log.Debug("Using config file: ", viper.ConfigFileUsed())
} else {
log.Fatal("Config file not found")
os.Exit(1)
if err := viper.ReadInConfig() ; err != nil {
log.Error("Config file not found:")
log.Fatal(err)
}
log.Debug("Using config file: ", viper.ConfigFileUsed())

configValidator("gitlab_project_id")
configValidator("gitlab_token")
Expand Down

0 comments on commit c63ec85

Please sign in to comment.