fix: respect $XDG_CONFIG_HOME
This commit is contained in:
parent
527f6bf15f
commit
2ea1bff59d
2 changed files with 17 additions and 0 deletions
|
|
@ -21,6 +21,9 @@ type HostConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfigDir() (string, error) {
|
func GetConfigDir() (string, error) {
|
||||||
|
if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" {
|
||||||
|
return filepath.Join(xdgConfigHome, "fgj"), nil
|
||||||
|
}
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,20 @@ func TestGetConfigDir(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetConfigDir_XDG(t *testing.T) {
|
||||||
|
t.Setenv("XDG_CONFIG_HOME", "/custom/config")
|
||||||
|
|
||||||
|
dir, err := GetConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := "/custom/config/fgj"
|
||||||
|
if dir != expected {
|
||||||
|
t.Errorf("Expected %q, got %q", expected, dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetConfigPath(t *testing.T) {
|
func TestGetConfigPath(t *testing.T) {
|
||||||
path, err := GetConfigPath()
|
path, err := GetConfigPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue