~kota/metweather

0bd167957fca4143b731283655aba0cbf145f367 — Dakota Walsh 1 year, 10 months ago 85b1603
change config path to XDG_CONFIG
3 files changed, 11 insertions(+), 3 deletions(-)

M cmd/root.go
M go.mod
M go.sum
M cmd/root.go => cmd/root.go +8 -3
@@ 4,7 4,9 @@ import (
	"io"
	"log"
	"os"
	"path"

	"github.com/adrg/xdg"
	homedir "github.com/mitchellh/go-homedir"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"


@@ 23,7 25,7 @@ var rootCmd = &cobra.Command{

func init() {
	cobra.OnInitialize(initConfig)
	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.metweather.yaml)")
	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $XDG_CONFIG/.metweather.yaml)")
	log.SetPrefix("metweather error: ")
	log.SetFlags(0)
}


@@ 41,8 43,11 @@ func initConfig() {
			os.Exit(1)
		}

		// Search config in home directory with name ".metweather" (without extension).
		viper.AddConfigPath(home)
		// Search config in XDG_CONFIG directories with name ".metweather"
		// (without extension).
		viper.AddConfigPath("/etc/metweather/")
		viper.AddConfigPath(xdg.ConfigHome)
		viper.AddConfigPath(path.Join(home, ".config"))
		viper.SetConfigName(".metweather")
	}


M go.mod => go.mod +1 -0
@@ 4,6 4,7 @@ go 1.16

require (
	git.sr.ht/~kota/metservice-go v1.0.1
	github.com/adrg/xdg v0.3.3
	github.com/mitchellh/go-homedir v1.1.0
	github.com/spf13/cast v1.4.0 // indirect
	github.com/spf13/cobra v1.2.1

M go.sum => go.sum +2 -0
@@ 41,6 41,8 @@ git.sr.ht/~kota/metservice-go v1.0.1 h1:XjQjIgBywJ3la2RQnpeU82WGU9oEnsJ+8Sch0vb8
git.sr.ht/~kota/metservice-go v1.0.1/go.mod h1:ruGNU5HLsIa4TPYAiB2FHPUTk3Ya4/uRT06/OLCZB4c=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/adrg/xdg v0.3.3 h1:s/tV7MdqQnzB1nKY8aqHvAMD+uCiuEDzVB5HLRY849U=
github.com/adrg/xdg v0.3.3/go.mod h1:61xAR2VZcggl2St4O9ohF5qCKe08+JDmE4VNzPFQvOQ=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=