summaryrefslogtreecommitdiff
path: root/modes.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-05-17 01:37:24 +0200
committerewy <ewy0@protonmail.com>2026-05-17 01:37:24 +0200
commitf5807d9f3a6c96e70912b61fac17120f412b5782 (patch)
treed6928795e06b1af000ffba2ae50bb6f8f7b72685 /modes.go
parent7984fd9beaa7c903288142818cb328c584a139a5 (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 'modes.go')
-rw-r--r--modes.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/modes.go b/modes.go
index 5650f5c..bc9e90f 100644
--- a/modes.go
+++ b/modes.go
@@ -9,6 +9,7 @@ import (
"github.com/ewy1/pik/run"
"github.com/ewy1/pik/spool"
"os"
+ "path/filepath"
"runtime"
"runtime/pprof"
)
@@ -43,6 +44,8 @@ func (m ModeMap[T]) Traverse(then func(in T) error) error {
var profileFd *os.File
+var UnknownShellError = errors.New("$SHELL not set or empty")
+
// statelessModes are program modes which do not require state to operate.
// like --version and --completion
var statelessModes = ModeMap[func() error]{
@@ -50,6 +53,14 @@ var statelessModes = ModeMap[func() error]{
_, err := spool.Print("%s\n", version)
return err
},
+ flags.InstallCompletion: func() error {
+ sh := os.Getenv("SHELL")
+ if sh == "" {
+ return UnknownShellError
+ }
+ _, sh = filepath.Split(sh)
+ return completion.Add(sh)
+ },
flags.Completion: func() error {
return completion.Echo()
},
@@ -68,15 +79,24 @@ var statelessModes = ModeMap[func() error]{
},
}
+var NoTargetsError = errors.New("no targets or sources to list")
+
// statefulModes are program modes which require a built state to be executed
var statefulModes = ModeMap[func(st *model.State) error]{
flags.List: func(st *model.State) error {
+ count := 0
for _, s := range st.Sources {
+ count++
_, _ = spool.Print("%v", s.Label()+paths.Ifs)
for _, t := range s.Targets {
_, _ = spool.Print("%v", t.ShortestId()+paths.Ifs)
+ count++
}
}
+
+ if count == 0 {
+ return NoTargetsError
+ }
return nil
},
}