From 79a62c735e62348d3297bbbfa5738b6cf2dadd70 Mon Sep 17 00:00:00 2001 From: comp500 Date: Thu, 19 Sep 2019 01:22:59 +0100 Subject: [PATCH] Use UserConfigDir instead of $HOME go-homedir???! I be using go 1.13 now --- cmd/root.go | 17 ++++++++++------- go.mod | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 3d66333..cd7654a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,10 +3,9 @@ package cmd import ( "fmt" "os" + "path/filepath" "github.com/spf13/cobra" - - homedir "github.com/mitchellh/go-homedir" "github.com/spf13/viper" ) @@ -42,7 +41,13 @@ func init() { rootCmd.PersistentFlags().StringVar(&modsFolder, "mods-folder", "mods", "The default folder to store mod metadata files in") viper.BindPFlag("mods-folder", rootCmd.PersistentFlags().Lookup("mods-folder")) - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.packwiz.toml)") + file, err := os.UserConfigDir() + if err != nil { + fmt.Println(err) + os.Exit(1) + } + file = filepath.Join(file, "packwiz", ".packwiz.toml") + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "The config file to use (default \""+file+"\")") } // initConfig reads in config file and ENV variables if set. @@ -51,15 +56,13 @@ func initConfig() { // Use config file from the flag. viper.SetConfigFile(cfgFile) } else { - // Find home directory. - home, err := homedir.Dir() + dir, err := os.UserConfigDir() if err != nil { fmt.Println(err) os.Exit(1) } - // Search config in home directory with name ".packwiz" (without extension). - viper.AddConfigPath(home) + viper.AddConfigPath(filepath.Join(dir, "packwiz")) viper.SetConfigName(".packwiz") } diff --git a/go.mod b/go.mod index f769876..63b583f 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e // indirect github.com/igorsobreira/titlecase v0.0.0-20140109233139-4156b5b858ac github.com/mattn/go-isatty v0.0.4 // indirect - github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/mapstructure v1.1.2 github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e github.com/spf13/cobra v0.0.5