package config import ( "fmt" "strings" "yetano.dev/yetano/core" "yetano.dev/yetano/core/paths" ) // Explanation is the full, structured report for a doctor-style command // (spec sections 42/44/45): every configuration layer this Resolver // considered, plus the paths.Explanation for everything else (Data, // State, Cache, Runtime, Log, Bin). Building it never mutates the // filesystem. type Explanation struct { Application core.Application Filename string Layers []Layer Selected string // "", if no layer's file exists Paths paths.Explanation } // Explain resolves every configuration layer and every core/paths // category and returns a combined, structured report. func (r *Resolver) Explain() (Explanation, error) { layers, err := r.layers() if err != nil { return Explanation{}, err } pathsExplanation, err := r.paths.Explain() if err != nil { return Explanation{}, err } ex := Explanation{ Application: r.app, Filename: r.filename, Layers: layers, Paths: pathsExplanation, } for _, l := range layers { if l.Selected { ex.Selected = l.Path } } return ex, nil } // String renders a human-readable report similar to spec section 44. func (e Explanation) String() string { var b strings.Builder fmt.Fprintf(&b, "Application: %s\n", e.Application.Name) fmt.Fprintf(&b, "Kind: %s\n", e.Application.Kind) fmt.Fprintf(&b, "Scope: %s\n\n", e.Application.Scope) b.WriteString("Configuration layers:\n") for _, l := range e.Layers { found := "no" if l.Exists { found = "yes" } fmt.Fprintf(&b, " %s\n priority: %d\n source: %s\n found: %s\n", l.Path, l.Priority, l.Source, found) } b.WriteString("\n") if e.Selected != "" { fmt.Fprintf(&b, "Selected:\n %s\n\n", e.Selected) } else { b.WriteString("Selected:\n (none found)\n\n") } b.WriteString(e.Paths.String()) return b.String() }