Fourth slice of docs/prds/eda-playbook-engine.md (t2db.12): the design doc's pre-merge collision layer, as a gopls-shaped standalone binary (cmd/archie-playbooks) rather than a Taskfile wrapper -- one binary, one schema source, mode-based entrypoints. - cmd/archie-playbooks: subcommand dispatch table from day one (lint now; an lsp/serve mode later slots in without restructuring), flag parsing only per organisation.md's cmd/ rule. - internal/app/archieplaybooks: the lint mode's composition -- collects directories, calls workflow.LoadPlaybookDirs (the daemon's own loader), reports findings. No second validation path: the linter agrees with runtime startup validation by construction. - Reuses LoadKindWorkflowsYAML/LoadLabelWorkflowsYAML/LoadPlaybookDirs directly; collision/malformed/invalid bindings exit non-zero. - Known limitation recorded: findings are file-granular, not line-granular (yaml.Unmarshal into map discards line numbers; a file:line diagnostic needs a yaml.Node upgrade, out of scope here). - Taskfile lint:playbooks target; PRD records the shipped shape and the file-granular caveat.
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
// Package archieplaybooks is the application composition for the standalone
|
|
// playbook-validation CLI (cmd/archie-playbooks). It owns the lint mode's
|
|
// orchestration: collect the configured directories, run the domain
|
|
// validator, and shape the outcome for human consumption. All validation
|
|
// rules live in internal/domain/workflow (LoadKindWorkflowsYAML,
|
|
// LoadLabelWorkflowsYAML, LoadPlaybookDirs) -- this package only calls them
|
|
// and formats results; there is deliberately no second validation path
|
|
// here (per docs/prds/eda-playbook-engine.md and t2db.12).
|
|
package archieplaybooks
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
)
|
|
|
|
// Result is the outcome of one lint run: the exit code for the process and
|
|
// the human-readable findings.
|
|
type Result struct {
|
|
ExitCode int
|
|
Findings []string
|
|
}
|
|
|
|
// Lint validates one or more playbook directories against the domain
|
|
// loaders and reports every collision / malformed file / invalid binding as
|
|
// a finding. It returns exit code 0 on a clean set, 1 when any finding is
|
|
// reported. Directories and single-file fields share one validation source:
|
|
//
|
|
// workflow.LoadPlaybookDirs
|
|
//
|
|
// which already applies the same rules LoadKindWorkflowsYAML and
|
|
// LoadLabelWorkflowsYAML do, per file and across files -- so the linter can
|
|
// never disagree with the daemon's startup validation.
|
|
func Lint(dirs []string, stderr io.Writer) Result {
|
|
var findings []string
|
|
|
|
_, _, err := workflow.LoadPlaybookDirs(dirs)
|
|
if err != nil {
|
|
findings = append(findings, err.Error())
|
|
}
|
|
|
|
if len(findings) > 0 {
|
|
for _, f := range findings {
|
|
fmt.Fprintln(stderr, f)
|
|
}
|
|
return Result{ExitCode: 1, Findings: findings}
|
|
}
|
|
return Result{ExitCode: 0, Findings: nil}
|
|
}
|