summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cache/cache_test.go6
-rw-r--r--completion/completion.go8
-rw-r--r--env/env.go4
-rw-r--r--indexers/pikdex/index.go25
-rw-r--r--indexers/pikdex/index_test.go9
-rw-r--r--paths/roots.go21
-rw-r--r--runner/base.go4
-rw-r--r--runner/shell/shell.go6
8 files changed, 44 insertions, 39 deletions
diff --git a/cache/cache_test.go b/cache/cache_test.go
index d2792ca..204f670 100644
--- a/cache/cache_test.go
+++ b/cache/cache_test.go
@@ -210,16 +210,17 @@ func TestMergeNilNormal(t *testing.T) {
func TestCacheInit_Init(t *testing.T) {
d := t.TempDir()
paths.SetAll(d)
+ defer paths.Reset()
c := &cacheInit{}
err := c.Init()
assert.NoError(t, err)
- assert.Contains(t, paths.ContextsFile, d)
+ assert.Contains(t, paths.ContextsFile.String(), d)
}
func TestInsert(t *testing.T) {
d := t.TempDir()
st := TState(TSource("source", "target"))
- paths.SetAll(d)
+ paths.Set(paths.CacheDir, d)
defer paths.Reset()
err := MergeAndSave(st)
assert.NoError(t, err)
@@ -228,6 +229,7 @@ func TestInsert(t *testing.T) {
func TestInsertNonExistent(t *testing.T) {
st := TState(TSource("source", "target"))
paths.SetAll("/../")
+ defer paths.Reset()
err := MergeAndSave(st)
assert.Error(t, err)
}
diff --git a/completion/completion.go b/completion/completion.go
index f3d76d7..641eb8a 100644
--- a/completion/completion.go
+++ b/completion/completion.go
@@ -19,11 +19,11 @@ var completionFormat = `
%s
`
-var completionComment = "\n# pik completion (installed by `pik --install-completion`)\n"
+var completionComment = "pik completion (installed by `pik --install-completion`)"
var completionCodeByShell = map[string]string{
- "bash": ". <(pik --completion)\n\n",
- "zsh": `autoload -Uz compinit && compinit && source <(pik --completion)\n\n`,
+ "bash": ". <(pik --completion)",
+ "zsh": `autoload -Uz compinit && compinit && source <(pik --completion)`,
}
var completionFileByShell = map[string]string{
@@ -60,6 +60,6 @@ func successMessage(shell string, file string) {
}
func Echo() error {
- _, err := spool.Print(completionCode)
+ _, err := spool.Print("%s", completionCode)
return err
}
diff --git a/env/env.go b/env/env.go
index b39076d..ffc29bf 100644
--- a/env/env.go
+++ b/env/env.go
@@ -2,8 +2,8 @@ package env
import (
"github.com/ewy1/pik/flags"
- "github.com/ewy1/pik/indexers/pikdex"
"github.com/ewy1/pik/model"
+ "github.com/ewy1/pik/paths"
"github.com/ewy1/pik/spool"
"github.com/joho/godotenv"
"io/fs"
@@ -36,7 +36,7 @@ func Files(f fs.FS, p string, deep bool) []string {
return nil
}
for _, e := range dir {
- if e.IsDir() && slices.Contains(pikdex.Roots, e.Name()) && deep {
+ if e.IsDir() && slices.Contains(paths.Roots, e.Name()) && deep {
result = append(result, Files(f, e.Name(), false)...)
}
if !e.IsDir() && IsEnv(e.Name()) {
diff --git a/indexers/pikdex/index.go b/indexers/pikdex/index.go
index 64e76e6..70cfabb 100644
--- a/indexers/pikdex/index.go
+++ b/indexers/pikdex/index.go
@@ -3,6 +3,7 @@ package pikdex
import (
"errors"
"github.com/ewy1/pik/model"
+ "github.com/ewy1/pik/paths"
"github.com/ewy1/pik/spool"
"io/fs"
"os"
@@ -13,26 +14,6 @@ import (
"sync"
)
-var Roots = []string{
-
- // current name
- ".pik",
- "_pik",
-
- // program names from a previous life
- ".godo",
- "_godo",
- ".pik",
- "_uwu",
-
- //utility
- ".bin",
- "_bin",
- "tasks",
- ".tasks",
- "_tasks",
-}
-
var SkippedFolders = []string{
".git",
".config",
@@ -50,7 +31,7 @@ func (u *pikdex) Init() error {
return nil
}
self = strings.TrimSuffix(self, ".exe")
- Roots = append(Roots, "."+self, "_"+self)
+ paths.Roots = append(paths.Roots, "."+self, "_"+self)
return nil
}
@@ -163,7 +144,7 @@ func (u *pikdex) WantsWalk(f fs.FS) (bool, string, error) {
}
for _, e := range entries {
- for _, r := range Roots {
+ for _, r := range paths.Roots {
if e.Name() == r && e.IsDir() {
return true, r, nil
}
diff --git a/indexers/pikdex/index_test.go b/indexers/pikdex/index_test.go
index c49d67f..8a82e55 100644
--- a/indexers/pikdex/index_test.go
+++ b/indexers/pikdex/index_test.go
@@ -1,6 +1,7 @@
package pikdex
import (
+ "github.com/ewy1/pik/paths"
"github.com/stretchr/testify/assert"
"io/fs"
"testing"
@@ -8,7 +9,7 @@ import (
)
func TestUwudex_WantsWalk_AnyRoot(t *testing.T) {
- for _, r := range Roots {
+ for _, r := range paths.Roots {
data := fstest.MapFS{
r: &fstest.MapFile{
Data: nil,
@@ -25,11 +26,11 @@ func TestUwudex_WantsWalk_AnyRoot(t *testing.T) {
func TestUwudex_WantsWalk_TwoRoots(t *testing.T) {
data := fstest.MapFS{
- Roots[0]: &fstest.MapFile{
+ paths.Roots[0]: &fstest.MapFile{
Data: nil,
Mode: fs.ModeDir,
},
- Roots[1]: &fstest.MapFile{
+ paths.Roots[1]: &fstest.MapFile{
Data: nil,
Mode: fs.ModeDir,
},
@@ -37,7 +38,7 @@ func TestUwudex_WantsWalk_TwoRoots(t *testing.T) {
u := &pikdex{}
result, r, err := u.WantsWalk(data)
// no guarantee we pick any one lol
- assert.Contains(t, Roots, r)
+ assert.Contains(t, paths.Roots, r)
assert.NoError(t, err)
assert.True(t, result)
}
diff --git a/paths/roots.go b/paths/roots.go
new file mode 100644
index 0000000..8765e96
--- /dev/null
+++ b/paths/roots.go
@@ -0,0 +1,21 @@
+package paths
+
+var Roots = []string{
+
+ // current name
+ ".pik",
+ "_pik",
+
+ // program names from a previous life
+ ".godo",
+ "_godo",
+ ".pik",
+ "_uwu",
+
+ //utility
+ ".bin",
+ "_bin",
+ "tasks",
+ ".tasks",
+ "_tasks",
+}
diff --git a/runner/base.go b/runner/base.go
index b3013b3..4fcd3d0 100644
--- a/runner/base.go
+++ b/runner/base.go
@@ -2,8 +2,8 @@ package runner
import (
"github.com/ewy1/pik/identity"
- "github.com/ewy1/pik/indexers/pikdex"
"github.com/ewy1/pik/model"
+ "github.com/ewy1/pik/paths"
"path/filepath"
"slices"
"strings"
@@ -21,7 +21,7 @@ func SubFromFile(file string) []string {
var sub []string
split := strings.Split(file, "/")
for _, p := range split {
- if slices.Contains(pikdex.Roots, p) {
+ if slices.Contains(paths.Roots, p) {
continue
}
if filename == p {
diff --git a/runner/shell/shell.go b/runner/shell/shell.go
index 53b4df3..8bef032 100644
--- a/runner/shell/shell.go
+++ b/runner/shell/shell.go
@@ -4,8 +4,8 @@ import (
"bufio"
"errors"
"github.com/ewy1/pik/identity"
- "github.com/ewy1/pik/indexers/pikdex"
"github.com/ewy1/pik/model"
+ "github.com/ewy1/pik/paths"
"github.com/ewy1/pik/runner"
"github.com/ewy1/pik/spool"
"io/fs"
@@ -87,7 +87,7 @@ func (s *shell) CreateTarget(fs fs.FS, src string, file string, _ fs.DirEntry) (
var sub []string
split := strings.Split(file, "/")
for _, p := range split {
- if slices.Contains(pikdex.Roots, p) {
+ if slices.Contains(paths.Roots, p) {
continue
}
if filename == p {
@@ -133,7 +133,7 @@ func (s *shell) ShellFor(fs fs.FS, file string) (string, error) {
if loc, err := s.Find(potentialShell); err == nil {
shell = loc
} else {
- _, _ = spool.Warn("script has %s but could not find %s (%s)\n", shebang, potentialShell)
+ _, _ = spool.Warn("script has %s but could not find %s\n", shebang, potentialShell)
}
}
}