diff options
| author | ewy <ewy0@protonmail.com> | 2026-04-14 18:40:06 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-04-14 18:40:06 +0200 |
| commit | 5f1677f8e7e55e6a82974b4b6ce9a92164492859 (patch) | |
| tree | 8f1a506b3b92dd9d0210977d3979292e787b5f20 /runner/just/just.go | |
| parent | 38112fbdbfb6e003a0c22919dfda4bf0091150a0 (diff) | |
add just runner
+ update readme
Diffstat (limited to 'runner/just/just.go')
| -rw-r--r-- | runner/just/just.go | 93 |
1 files changed, 93 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 +} |
