Skip to content

Commit

Permalink
Use USERPROFILE on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
denik committed Jan 6, 2025
1 parent 50220d6 commit 73b86b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/databricks/cli/internal/testutil"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/testdiff"
"github.com/stretchr/testify/require"
)
Expand All @@ -32,7 +33,7 @@ func TestAll(t *testing.T) {
t.Setenv("DATABRICKS_TOKEN", "dapi1234")

homeDir := t.TempDir()
t.Setenv("HOME", homeDir)
t.Setenv(env.HomeEnvVar(), homeDir)

testDirs := getTests(t)
require.NotEmpty(t, testDirs)
Expand Down
6 changes: 3 additions & 3 deletions libs/env/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ func Set(ctx context.Context, key, value string) context.Context {
return setMap(ctx, m)
}

func homeEnvVar() string {
func HomeEnvVar() string {
if runtime.GOOS == "windows" {
return "USERPROFILE"
}
return "HOME"
}

func WithUserHomeDir(ctx context.Context, value string) context.Context {
return Set(ctx, homeEnvVar(), value)
return Set(ctx, HomeEnvVar(), value)
}

// ErrNoHomeEnv indicates the absence of $HOME env variable
var ErrNoHomeEnv = errors.New("$HOME is not set")

func UserHomeDir(ctx context.Context) (string, error) {
home := Get(ctx, homeEnvVar())
home := Get(ctx, HomeEnvVar())
if home == "" {
return "", ErrNoHomeEnv
}
Expand Down

0 comments on commit 73b86b5

Please sign in to comment.