summaryrefslogtreecommitdiff
path: root/runner
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-14 18:40:06 +0200
committerewy <ewy0@protonmail.com>2026-04-14 18:40:06 +0200
commit5f1677f8e7e55e6a82974b4b6ce9a92164492859 (patch)
tree8f1a506b3b92dd9d0210977d3979292e787b5f20 /runner
parent38112fbdbfb6e003a0c22919dfda4bf0091150a0 (diff)
add just runner
+ update readme
Diffstat (limited to 'runner')
-rw-r--r--runner/just/just.go93
-rw-r--r--runner/just/target.go41
2 files changed, 134 insertions, 0 deletions
diff --git a/runner/just/just.go b/runner/just/just.go
new file mode 100644
index 0000000..e574536
--- /dev/null
+++ b/runner/just/just.go
@@ -0,0 +1,93 @@
+package just
+
+import (
+ "io/fs"
+ "os/exec"
+ "pik/identity"
+ "pik/model"
+ "pik/runner"
+ "strings"
+)
+
+type just struct {
+ path string
+}
+
+var Indexer = &just{}
+
+func (j *just) Index(path string, f fs.FS, runners []model.Runner) ([]model.Target, error) {
+
+ entries, err := fs.ReadDir(f, ".")
+ if err != nil {
+ return nil, err
+ }
+ hasJustfile := false
+ for _, e := range entries {
+ if !e.IsDir() && strings.ToLower(e.Name()) == "justfile" {
+ hasJustfile = true
+ break
+ }
+ }
+
+ if !hasJustfile {
+ return nil, nil
+ }
+
+ err = j.findJust()
+ if err != nil {
+ return nil, err
+ }
+
+ cmd := exec.Command(j.path, "--list")
+ cmd.Dir = path
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ return nil, err
+ }
+ return ParseOutput(string(out)), nil
+}
+
+func ParseOutput(input string) []model.Target {
+ categories := make(map[string][]string)
+ currentCategory := ""
+ for _, line := range strings.Split(input, "\n") {
+ // strip comment
+ line = strings.SplitN(line, "#", 2)[0]
+ line = strings.TrimSpace(line)
+
+ if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
+ currentCategory = line[1 : len(line)-1]
+ continue
+ }
+
+ tgt := strings.SplitN(line, " ", 2)[0]
+
+ if tgt == "" {
+ continue
+ }
+
+ categories[currentCategory] = append(categories[currentCategory], tgt)
+ }
+
+ var result []model.Target
+ for c, targets := range categories {
+ for _, t := range targets {
+ result = append(result, &JustTarget{
+ BaseTarget: runner.BaseTarget{
+ Identity: identity.New(t),
+ },
+ Category: c,
+ })
+ }
+ }
+ return result
+}
+
+func (j *just) findJust() error {
+ loc, err := exec.LookPath("just")
+ if err != nil {
+ return err
+ }
+ j.path = loc
+ return nil
+}
diff --git a/runner/just/target.go b/runner/just/target.go
new file mode 100644
index 0000000..c36e4af
--- /dev/null
+++ b/runner/just/target.go
@@ -0,0 +1,41 @@
+package just
+
+import (
+ "os/exec"
+ "pik/model"
+ "pik/runner"
+)
+
+type JustTarget struct {
+ runner.BaseTarget
+ Category string
+}
+
+func (j JustTarget) Create(s *model.Source) *exec.Cmd {
+ return exec.Command(Indexer.path, j.Identity.Full)
+}
+
+func (j JustTarget) Sub() []string {
+ if j.Category != "" {
+ return []string{j.Category}
+ }
+ return nil
+}
+
+func (j JustTarget) Label() string {
+ return j.Identity.Full
+}
+
+func (j *JustTarget) Hydrate(src *model.Source) (model.HydratedTarget, error) {
+ return &HydratedJustTarget{
+ BaseHydration: runner.Hydrated(j),
+ }, nil
+}
+
+type HydratedJustTarget struct {
+ runner.BaseHydration[*JustTarget]
+}
+
+func (h *HydratedJustTarget) Icon() string {
+ return "\uF039"
+}