cmd: handle relative paths to the config file (#180)
This commit is contained in:
parent
9b341db2db
commit
9ffbcdcdb1
10
cmd/root.go
10
cmd/root.go
|
@ -13,7 +13,6 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/NYTimes/logrotate"
|
"github.com/NYTimes/logrotate"
|
||||||
|
@ -379,13 +378,14 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
|
||||||
// Reads the configuration from the disk and then sets up the global singleton
|
// Reads the configuration from the disk and then sets up the global singleton
|
||||||
// with all the configuration values.
|
// with all the configuration values.
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
if !strings.HasPrefix(configPath, "/") {
|
if !filepath.IsAbs(configPath) {
|
||||||
d, err := os.Getwd()
|
d, err := filepath.Abs(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log2.Fatalf("cmd/root: could not determine directory: %s", err)
|
log2.Fatalf("cmd/root: failed to get path to config file: %s", err)
|
||||||
}
|
}
|
||||||
configPath = path.Clean(path.Join(d, configPath))
|
configPath = d
|
||||||
}
|
}
|
||||||
|
|
||||||
err := config.FromFile(configPath)
|
err := config.FromFile(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user