completion, doctor: the shared standard commands

core/completion prints bash, zsh, fish or PowerShell completion scripts
from a static command tree ("<program> completion <shell>"); core/doctor
is one report shape (resolved paths incl. the standard core/paths ones,
named checks), printed as a table or --json, exit 0/1/2. Together with
core/manual they implement the Yetano program standard
(docs/program-conventions.md in the meta-repo).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-10-07 16:30:45 +02:00
1 parent e757fdd025
commit 13c1862c74
5 files changed
+479

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
package doctor
import (
"encoding/json"
"errors"
"path/filepath"
"strings"
"testing"
"yetano.dev/yetano/core"
)
func TestRun(t *testing.T) {
dir := t.TempDir()
r := Report{Program: "tool"}
r.AddPath("data dir", dir, nil)
r.AddPath("missing", filepath.Join(dir, "nope"), nil)
r.AddPath("broken", "", errors.New("no home"))
r.Check("config valid", true, "")
var out, errOut strings.Builder
if code := r.Run([]string{"--json"}, &out, &errOut); code != ExitOK {
t.Fatalf("exit %d: %s", code, errOut.String())
}
var got Report
if err := json.Unmarshal([]byte(out.String()), &got); err != nil || len(got.Paths) != 3 || !got.Paths[0].Exists || got.Paths[1].Exists || got.Paths[2].Error != "no home" {
t.Fatalf("json: %v %+v", err, got)
}
r.Check("listener port free", false, "port 514 in use")
out.Reset()
if code := r.Run(nil, &out, &errOut); code != ExitProblems || !strings.Contains(out.String(), "port 514 in use") || !strings.Contains(errOut.String(), "1 problem") {
t.Fatalf("problems: %d %q %q", code, out.String(), errOut.String())
}
if code := r.Run([]string{"--bogus"}, &out, &errOut); code != ExitUsage {
t.Fatalf("usage: %d", code)
}
}
func TestAddPaths(t *testing.T) {
var r Report
r.AddPaths(core.Application{Name: "doctor-test", Kind: core.CLI})
if r.Scope != "user" || len(r.Paths) < 5 || r.Paths[0].Name != "config dir" {
t.Fatalf("paths: %+v", r)
}
for _, p := range r.Paths {
if p.Error == "" && p.Path == "" {
t.Errorf("%s: no path", p.Name)
}
}
}