You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ecctl should be able to read a config file located at $XDG_CONFIG_HOME/ecctl/config.{json,yaml,toml,hcl} (by convention, $HOME/.config/ecctl/config.{json,yaml,toml,hcl}) in line with the XDG Base Directory Specification.
Adding viper.AddConfigPath("$XDG_CONFIG_HOME/ecctl") to func setupVipershould do the trick:
diff --git a/cmd/root.go b/cmd/root.go
index 1a50581..d5cc47c 100644
--- a/cmd/root.go+++ b/cmd/root.go@@ -137,6 +137,7 @@ func setupViper(v *viper.Viper) {
v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
v.AutomaticEnv()
v.AddConfigPath(ecctlHomePath) // adding home directory as first search path
+ v.AddConfigPath("$XDG_CONFIG_HOME/ecctl")
v.SetConfigName(v.GetString("config")) // name of config file (without extension)
// If a config file is found, read it in.
A more thorough implementation might be to split up ecctlHomePath to different variables that could also be used in case the tool needs to store user data or cache data ($XDG_DATA_HOME and $XDG_CACHE_HOME, respectively), rather than making the assumption they'll all be in the same ~/.ecctl directory.
Testing
Test that if $XDG_CONFIG_HOME is defined, ecctl init writes the config file in that directory.
Test that if $XDG_CONFIG_HOME is defined and $XDG_CONFIG_HOME/ecctl/config.json exists, it is used for configuration values.
Test that if both $XDG_CONFIG_HOME/ecctl/config.json and $HOME/.ecctl/config.json exist, the latter takes priority (I think? It depends on the implementation and which is given higher precedence)
Test that if $XDG_CONFIG_HOME is defined and $XDG_CONFIG_HOME/ecctl/config.json doesn't exist, it falls back to $HOME/.ecctl/config.json if it exists, otherwise the missing ecctl config file message is diplayed.
Context
I try to keep my $HOME directory free of extraneous dotfiles/directories.
Your Environment
macOS (but any Linux/Unix variant will be similarly affected).
The text was updated successfully, but these errors were encountered:
Overview
ecctl should be able to read a config file located at
$XDG_CONFIG_HOME/ecctl/config.{json,yaml,toml,hcl}
(by convention,$HOME/.config/ecctl/config.{json,yaml,toml,hcl}
) in line with the XDG Base Directory Specification.Possible Implementation
Caveat: I'm not a Golang developer.
It seem like Viper supports this, but not implicitly.
Adding
viper.AddConfigPath("$XDG_CONFIG_HOME/ecctl")
tofunc setupViper
should do the trick:A more thorough implementation might be to split up
ecctlHomePath
to different variables that could also be used in case the tool needs to store user data or cache data ($XDG_DATA_HOME
and$XDG_CACHE_HOME
, respectively), rather than making the assumption they'll all be in the same~/.ecctl
directory.Testing
$XDG_CONFIG_HOME
is defined,ecctl init
writes the config file in that directory.$XDG_CONFIG_HOME
is defined and$XDG_CONFIG_HOME/ecctl/config.json
exists, it is used for configuration values.$XDG_CONFIG_HOME/ecctl/config.json
and$HOME/.ecctl/config.json
exist, the latter takes priority (I think? It depends on the implementation and which is given higher precedence)$XDG_CONFIG_HOME
is defined and$XDG_CONFIG_HOME/ecctl/config.json
doesn't exist, it falls back to$HOME/.ecctl/config.json
if it exists, otherwise themissing ecctl config file
message is diplayed.Context
I try to keep my
$HOME
directory free of extraneous dotfiles/directories.Your Environment
macOS (but any Linux/Unix variant will be similarly affected).
The text was updated successfully, but these errors were encountered: