Skip to content

Commit

Permalink
cmd: handle relative paths to the config file (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
danny6167 authored May 13, 2024
1 parent 9b341db commit 9ffbcdc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/NYTimes/logrotate"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9ffbcdc

Please sign in to comment.