diff --git a/internal/config/config_file.go b/internal/config/config_file.go index 9804aec36..4e434967c 100644 --- a/internal/config/config_file.go +++ b/internal/config/config_file.go @@ -14,6 +14,10 @@ import ( "gopkg.in/yaml.v3" ) +const ( + GH_CONFIG_DIR = "GH_CONFIG_DIR" +) + func ConfigDir() string { homeDir, _ := homeDirAutoMigrate() return homeDir @@ -263,3 +267,10 @@ func findRegularFile(p string) string { } return "" } + +func configPath() string { + if v := os.Getenv(GH_CONFIG_DIR); v != "" { + return v + } + return "~/.config/gh" +} diff --git a/internal/config/config_file_test.go b/internal/config/config_file_test.go index 35ecabda4..76181c1e1 100644 --- a/internal/config/config_file_test.go +++ b/internal/config/config_file_test.go @@ -3,6 +3,7 @@ package config import ( "bytes" "fmt" + "os" "testing" "github.com/stretchr/testify/assert" @@ -146,3 +147,23 @@ func Test_parseConfigFile(t *testing.T) { }) } } + +func Test_configPath(t *testing.T) { + tests := []struct { + envVar string + want string + }{ + {"/tmp/gh", "/tmp/gh"}, + {"", "~/.config/gh"}, + } + + for _, tt := range tests { + t.Run(fmt.Sprintf("envVar: %q", tt.envVar), func(t *testing.T) { + if tt.envVar != "" { + os.Setenv(GH_CONFIG_DIR, tt.envVar) + defer os.Unsetenv(GH_CONFIG_DIR) + } + eq(t, configPath(), tt.want) + }) + } +}