Merge pull request 'fix: respect $XDG_CONFIG_HOME' (#34) from fix/issue-33/respect_xdg_base_dir into main
Reviewed-on: https://codeberg.org/romaintb/fgj/pulls/34
This commit is contained in:
commit
73d54fde9c
2 changed files with 17 additions and 0 deletions
|
|
@ -21,6 +21,9 @@ type HostConfig struct {
|
|||
}
|
||||
|
||||
func GetConfigDir() (string, error) {
|
||||
if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" {
|
||||
return filepath.Join(xdgConfigHome, "fgj"), nil
|
||||
}
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
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) {
|
||||
path, err := GetConfigPath()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue