Connect report rendering to invocation outcomes

This commit is contained in:
2026-11-07 03:41:21 +00:00
parent 190bfbd77b
commit 3a6c66f550
3 changed files with 108 additions and 5 deletions

View File

@@ -41,6 +41,7 @@ type reportingState struct {
diagnostics destinationState
closed bool
mode reportingMode
format Format
progress bool
progressSet bool
deferred []deferredMessage
@@ -68,10 +69,10 @@ type deferredMessage struct {
// reenter the same reporter, and their supplied writer is valid only while the
// callback runs.
//
// Consumers use Output for substantive command results and the reporting
// methods for categorized messages. Delivery and rendering failures are
// retained for Outcome.Presentation even when a caller ignores an immediate
// method's returned error.
// Consumers use Report for formatted substantive results, Output or
// RenderOutput for deliberate raw output, and the reporting methods for
// categorized messages. Delivery and rendering failures are retained for
// Outcome.Presentation even when a caller ignores an immediate method's error.
type Reporter struct {
state *reportingState
}
@@ -153,6 +154,16 @@ func (w managedOutputWriter) Write(p []byte) (int, error) {
return w.state.write(w.destination, p)
}
// Report renders and delivers substantive content using the invocation's
// selected format. Rendering runs even when output is suppressed, and its
// failures are recorded separately from the operation outcome. Report must
// not be called from a rendering callback on the same reporter.
func (r *Reporter) Report(report Report) error {
return r.RenderOutput(func(w io.Writer) error {
return RenderReport(w, report, r.state.format)
})
}
// RenderOutput coordinates a complete substantive report rendering operation.
// The callback receives a writer usable only during the callback and must not
// reenter this reporter. In quiet mode, the callback still runs against a