Skip to content

Commit

Permalink
fix: correct config path
Browse files Browse the repository at this point in the history
Set the default config path to $XDG_CONFIG_HOME/evcli/config.yaml. This
aligns with our other clients (cocli an pocli), and with Unix best
practices.

Signed-off-by: Sergei Trofimov <[email protected]>
  • Loading branch information
setrofim committed Aug 21, 2024
1 parent 40dfa3d commit 86d1289
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
"github.com/veraison/evcli/v2/cmd/cca"
Expand Down Expand Up @@ -36,7 +37,7 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.evcli)")
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $XDG_CONFIG_HOME/evcli/config.yaml)")

rootCmd.AddCommand(psa.Cmd)
rootCmd.AddCommand(cca.Cmd)
Expand All @@ -47,13 +48,16 @@ func initConfig() {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
home, err := os.UserHomeDir()
wd, err := os.Getwd()
cobra.CheckErr(err)

// search config in home directory with name ".evcli" (without extension)
viper.AddConfigPath(home)
userConfigDir, err := os.UserConfigDir()
if err == nil {
viper.AddConfigPath(filepath.Join(userConfigDir, "evcli"))
}
viper.AddConfigPath(wd)
viper.SetConfigType("yaml")
viper.SetConfigName(".evcli")
viper.SetConfigName("config")
}

viper.AutomaticEnv() // read in environment variables that match
Expand Down
Binary file added misc/token.cbor
Binary file not shown.

0 comments on commit 86d1289

Please sign in to comment.