Fix --config flag

This commit is contained in:
Richard Patel 2019-02-03 03:17:22 +01:00
parent 120c026983
commit 0ca6deede8
No known key found for this signature in database
GPG Key ID: C268B2BBDA2ABECB

View File

@ -7,7 +7,6 @@ import (
"github.com/spf13/viper"
"io"
"os"
"path/filepath"
"strings"
"time"
)
@ -135,17 +134,23 @@ func prepareConfig() {
func readConfig() {
// If config.yml in working dir, use it
if _, err := os.Stat("config.yml"); err == nil {
configFile = "config.yml"
if configFile == "" {
_, err := os.Stat("config.yml")
if err == nil {
configFile = "config.yml"
}
}
if configFile != "" {
var err error
confPath, err := filepath.Abs(configFile)
if err != nil { panic(err) }
confF, err := os.Open(configFile)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
defer confF.Close()
viper.SetConfigFile(confPath)
err = viper.ReadInConfig()
viper.SetConfigType("yml")
err = viper.ReadConfig(confF)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)