From 9ffbcdcdb1163da823cf9959b9602df9f7dcb54a Mon Sep 17 00:00:00 2001 From: Daniel Barton Date: Tue, 14 May 2024 05:53:33 +0800 Subject: [PATCH] cmd: handle relative paths to the config file (#180) --- cmd/root.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 6aa7d6d..4635d9a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,7 +13,6 @@ import ( "path/filepath" "runtime" "strconv" - "strings" "time" "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 // with all the configuration values. func initConfig() { - if !strings.HasPrefix(configPath, "/") { - d, err := os.Getwd() + if !filepath.IsAbs(configPath) { + d, err := filepath.Abs(configPath) 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) if err != nil { if errors.Is(err, os.ErrNotExist) {