Skip to content

Commit 2bcbb86

Browse files
authored
use xdg config home instead of xdg runtime dir (#50)
Fixes #36
1 parent 174dc0e commit 2bcbb86

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

go-ssh-keysign/internal/cli/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func ReadConfigFile(cmd *cobra.Command, v *viper.Viper) error {
7474
} else {
7575
switch cmd.Name() {
7676
case "user":
77-
if runtimeDir := os.Getenv("XDG_RUNTIME_DIR"); runtimeDir != "" {
77+
if runtimeDir := os.Getenv("XDG_CONFIG_HOME"); runtimeDir != "" {
7878
v.SetConfigFile(filepath.Join(runtimeDir, constants.AppName, constants.ConfigFileName))
7979
} else if home, err := os.UserHomeDir(); err == nil && home != "" {
8080
v.SetConfigFile(filepath.Join(home, ".config", constants.AppName, constants.ConfigFileName))

go-ssh-keysign/internal/cli/testutil/helper.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ func ExecuteCommand(t *testing.T, cmd *cobra.Command, args ...string) (stoutStr,
8787
}
8888
}()
8989

90+
tempPath, err := os.MkdirTemp(os.TempDir(), "*")
91+
if err != nil {
92+
t.Fatalf("error creating temporary config directory: %v", err)
93+
}
94+
95+
if err := os.Setenv("XDG_CONFIG_HOME", tempPath); err != nil {
96+
t.Fatalf("setenv: %v", err)
97+
}
98+
9099
err = cmd.Execute()
91100
logs = observed.All()
92101
return stdout.String(), stderr.String(), logs, err

0 commit comments

Comments
 (0)