Skip to content

Commit 7a14cb8

Browse files
authored
[xdg]: unexport xxxDir() and use xxxSubpath() only (#733)
## Summary 1. Unexport `xxxDir()`s 2. Use `xxxSubpath()` outside of pckage `xdg` 3. update `rcfilePath` based on `resolveDir` ## How was it tested? tests
1 parent 46f8411 commit 7a14cb8

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

internal/impl/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func rcfilePath(basename string) string {
246246
}
247247

248248
func fishConfig() string {
249-
return filepath.Join(xdg.ConfigDir(), "fish", "config.fish")
249+
return xdg.ConfigSubpath("fish/config.fish")
250250
}
251251

252252
func (s *DevboxShell) Run() error {

internal/impl/shellcmd/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (c CmdFormat) String() string {
3333
}
3434
}
3535

36-
// ConfigShellCmds marshals and unmarshals shell commands from a devbox config
36+
// Commands marshals and unmarshals shell commands from a devbox config
3737
// as either a single string or an array of strings. It preserves the original
3838
// value such that:
3939
//

internal/xdg/xdg.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,27 @@ import (
55
"path/filepath"
66
)
77

8-
func DataDir() string {
9-
return resolveDir("XDG_DATA_HOME", ".local/share")
10-
}
11-
128
func DataSubpath(subpath string) string {
13-
return filepath.Join(DataDir(), subpath)
14-
}
15-
16-
func ConfigDir() string {
17-
return resolveDir("XDG_CONFIG_HOME", ".config")
9+
return filepath.Join(dataDir(), subpath)
1810
}
1911

2012
func ConfigSubpath(subpath string) string {
21-
return filepath.Join(ConfigDir(), subpath)
22-
}
23-
24-
func CacheDir() string {
25-
return resolveDir("XDG_CACHE_HOME", ".cache")
13+
return filepath.Join(configDir(), subpath)
2614
}
2715

2816
func CacheSubpath(subpath string) string {
29-
return filepath.Join(CacheDir(), subpath)
30-
}
31-
32-
func StateDir() string {
33-
return resolveDir("XDG_STATE_HOME", ".local/state")
17+
return filepath.Join(cacheDir(), subpath)
3418
}
3519

3620
func StateSubpath(subpath string) string {
37-
return filepath.Join(StateDir(), subpath)
21+
return filepath.Join(stateDir(), subpath)
3822
}
3923

24+
func dataDir() string { return resolveDir("XDG_DATA_HOME", ".local/share") }
25+
func configDir() string { return resolveDir("XDG_CONFIG_HOME", ".config") }
26+
func cacheDir() string { return resolveDir("XDG_CACHE_HOME", ".cache") }
27+
func stateDir() string { return resolveDir("XDG_STATE_HOME", ".local/state") }
28+
4029
func resolveDir(envvar string, defaultPath string) string {
4130
dir := os.Getenv(envvar)
4231
if dir != "" {

0 commit comments

Comments
 (0)