Skip to content

Commit

Permalink
fix: Moving config location
Browse files Browse the repository at this point in the history
  • Loading branch information
NoUseFreak committed Dec 27, 2023
1 parent dd6987d commit 2df4012
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@ package cmd

import (
"os"
"path/filepath"

"github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)



func initConfig() {
home, err := homedir.Dir()
if err != nil {
logrus.Error(err)
os.Exit(1)
}
viper.SetConfigName("warpdir")
viper.AddConfigPath(home + "/.config/warpdir")
viper.AddConfigPath(home)

if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
viper.AddConfigPath(home)
viper.SetConfigName(".warpdir")
}

if err := viper.ReadInConfig(); err != nil {
logrus.Warn(err)
logrus.Warn(err)
cfgFile = home + "/.config/warpdir/warpdir.yaml"
if err := os.MkdirAll(filepath.Dir(cfgFile), 0755); err != nil {
logrus.Error(err)
os.Exit(1)
}
if err := viper.SafeWriteConfigAs(cfgFile); err != nil {
logrus.Error(err)
os.Exit(1)
Expand Down

0 comments on commit 2df4012

Please sign in to comment.