doctor: optional per-check area and hint
Check gets Area and Hint, omitted from the JSON when empty; the table only grows an AREA or HINT column when some check uses one, so existing reports are unchanged. Report.Add records a check with all fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
131d82642c
commit
3d286da90d
4 files changed
+72
-4
No files matched your search
+31
-3
@@ -36,11 +36,16 @@ type Path struct {
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// Check is one named check.
|
||||
// Check is one named check. Area (a group such as "config" or
|
||||
// "services") and Hint (what to do about a failed check) are optional
|
||||
// and omitted from the JSON form when empty, so a report without them
|
||||
// looks exactly as before they existed.
|
||||
type Check struct {
|
||||
Area string `json:"area,omitempty"`
|
||||
Name string `json:"name"`
|
||||
OK bool `json:"ok"`
|
||||
Note string `json:"note,omitempty"`
|
||||
Hint string `json:"hint,omitempty"`
|
||||
}
|
||||
|
||||
// Report is "<program> doctor --json"'s output.
|
||||
@@ -110,6 +115,12 @@ func (r *Report) Check(name string, ok bool, note string) {
|
||||
r.Checks = append(r.Checks, Check{Name: name, OK: ok, Note: note})
|
||||
}
|
||||
|
||||
// Add records a check with all its fields, for a program that groups its
|
||||
// checks into areas or gives hints.
|
||||
func (r *Report) Add(c Check) {
|
||||
r.Checks = append(r.Checks, c)
|
||||
}
|
||||
|
||||
// Problems counts failed checks.
|
||||
func (r Report) Problems() int {
|
||||
n := 0
|
||||
@@ -148,9 +159,26 @@ func (r Report) Write(w io.Writer, asJSON bool) error {
|
||||
}
|
||||
fmt.Fprintln(tw)
|
||||
}
|
||||
fmt.Fprintf(tw, "CHECK\tOK\tNOTE\n")
|
||||
// The AREA and HINT columns only appear when some check uses them,
|
||||
// so the table of a program without them is unchanged.
|
||||
withArea, withHint := false, false
|
||||
for _, c := range r.Checks {
|
||||
fmt.Fprintf(tw, "%s\t%s\t%s\n", c.Name, yesNo(c.OK), c.Note)
|
||||
withArea = withArea || c.Area != ""
|
||||
withHint = withHint || c.Hint != ""
|
||||
}
|
||||
row := func(area, name, ok, note, hint string) {
|
||||
cols := []string{name, ok, note}
|
||||
if withArea {
|
||||
cols = append([]string{area}, cols...)
|
||||
}
|
||||
if withHint {
|
||||
cols = append(cols, hint)
|
||||
}
|
||||
fmt.Fprintln(tw, strings.Join(cols, "\t"))
|
||||
}
|
||||
row("AREA", "CHECK", "OK", "NOTE", "HINT")
|
||||
for _, c := range r.Checks {
|
||||
row(c.Area, c.Name, yesNo(c.OK), c.Note, c.Hint)
|
||||
}
|
||||
return tw.Flush()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user