Skip to content
This repository was archived by the owner on Mar 27, 2018. It is now read-only.

Commit f69741c

Browse files
committed
This should fix the path issue.
1 parent 6fd1471 commit f69741c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

cmd/root.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import (
1919
"os"
2020
"encoding/json"
2121
"runtime"
22+
"strings"
23+
"path/filepath"
2224

2325
"github.com/op/go-logging"
2426
"github.com/spf13/cobra"
2527
"github.com/spf13/viper"
2628
"github.com/oscp/openshift-monitoring-checks/checks"
27-
"strings"
28-
"path"
2929
)
3030

3131
var pretty bool
@@ -98,13 +98,18 @@ func initLogging() {
9898
}
9999

100100
func initConfig() {
101-
_, filename, _, _ := runtime.Caller(0)
101+
ex, err := os.Executable()
102+
103+
if err != nil {
104+
log.Critical(err)
105+
os.Exit(1)
106+
}
102107

103-
viper.AddConfigPath(path.Dir(filename)+"/..")
108+
viper.AddConfigPath(filepath.Dir(ex))
104109
viper.SetConfigName("config")
105110

106111
if err := viper.ReadInConfig(); err != nil {
107-
log.Error("Not able to read config file (path of script is ", path.Dir(filename)+")", viper.ConfigFileUsed()+".")
112+
log.Error("Not able to read config file (path of script is", filepath.Dir(ex)+")", "config.yml.")
108113
}
109114

110115
}

0 commit comments

Comments
 (0)