diff options
| author | ewy <ewy0@protonmail.com> | 2026-05-17 01:37:24 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-05-17 01:37:24 +0200 |
| commit | f5807d9f3a6c96e70912b61fac17120f412b5782 (patch) | |
| tree | d6928795e06b1af000ffba2ae50bb6f8f7b72685 /paths/paths.go | |
| parent | 7984fd9beaa7c903288142818cb328c584a139a5 (diff) | |
* integration tests with a pik target to run them
* add abstraction for paths to facilitate unit tests
* flesh out completion (--install-completion)
* do sync init before stateless modes so list knows more
Diffstat (limited to 'paths/paths.go')
| -rw-r--r-- | paths/paths.go | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/paths/paths.go b/paths/paths.go index cc0c878..b714a23 100644 --- a/paths/paths.go +++ b/paths/paths.go @@ -3,23 +3,39 @@ package paths import ( "github.com/adrg/xdg" "os" + "path" "path/filepath" "strings" ) var ( - Ifs string - Config string - Cache string - This string - Home string + Ifs string + ConfigDir = Empty() + CacheDir = Empty() + ContextsFile = Empty() + HomeDir = Empty() + System = Empty() + This = "pik" ) +var Paths = []*Path{ + ConfigDir, + CacheDir, + ContextsFile, + HomeDir, + System, +} + +var DirectoriesToMake = []*Path{ + ConfigDir, + CacheDir, +} + type paths struct { Initialized bool } -var Paths = &paths{ +var Component = &paths{ Initialized: false, } @@ -31,20 +47,21 @@ func (p *paths) Init() error { xdg.Reload() } - Home = xdg.Home - This = "pik" - Cache = filepath.Join(xdg.CacheHome, This) - Config = filepath.Join(xdg.ConfigHome, This) + HomeDir.Set(xdg.Home) + CacheDir.Set(filepath.Join(xdg.CacheHome, This)) + ConfigDir.Set(filepath.Join(xdg.ConfigHome, This)) + ContextsFile.Set(path.Join(CacheDir.String(), "contexts")) + System.Set(path.Join(ConfigDir.String())) + Ifs = os.Getenv("IFS") - err := os.MkdirAll(Cache, 0700) - if err != nil { - return err - } - err = os.MkdirAll(Config, 0700) - if err != nil { - return err + for _, d := range DirectoriesToMake { + err := os.MkdirAll(d.String(), 0700) + if err != nil { + return err + } } + if Ifs == "" { Ifs = "\n" } @@ -53,5 +70,5 @@ func (p *paths) Init() error { } func ReplaceHome(input string) string { - return strings.Replace(input, Home, "~", 1) + return strings.Replace(input, HomeDir.String(), "~", 1) } |
