2026-11-20 05:59:09 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
|
|
|
|
|
"go.maximumdirect.net/commandkit"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Native reporting retains its own delivery failures until invocation finalization.
|
|
|
|
|
// Console delivery failures must not interrupt domain work or checkpoint saves.
|
|
|
|
|
type nativeConsole struct{ reporter *commandkit.Reporter }
|
|
|
|
|
|
|
|
|
|
func (r nativeConsole) Info(message string, fields ...any) {
|
|
|
|
|
_ = r.reporter.Info(message, consoleFields(fields))
|
|
|
|
|
}
|
|
|
|
|
func (r nativeConsole) Warn(message string, fields ...any) {
|
|
|
|
|
_ = r.reporter.Warn(message, consoleFields(fields))
|
|
|
|
|
}
|
|
|
|
|
func (r nativeConsole) Debug(message string, fields ...any) {
|
|
|
|
|
_ = r.reporter.Debug(message, consoleFields(fields))
|
|
|
|
|
}
|
|
|
|
|
func (r nativeConsole) Progress(message string, fields ...any) {
|
|
|
|
|
_ = r.reporter.Progress(message, consoleFields(fields))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func consoleFields(fields []any) commandkit.Detail {
|
|
|
|
|
if len(fields) == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return func(w io.Writer) error {
|
|
|
|
|
for index := 0; index < len(fields); index += 2 {
|
|
|
|
|
value := any("")
|
|
|
|
|
if index+1 < len(fields) {
|
|
|
|
|
value = fields[index+1]
|
|
|
|
|
}
|
|
|
|
|
if _, err := fmt.Fprintf(w, "%v=%v\n", fields[index], value); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func withCommandReporting(deps commandDependencies, invocation commandkit.Invocation) commandDependencies {
|
|
|
|
|
deps.reporter = nativeConsole{reporter: invocation.Reporter()}
|
2026-11-20 06:32:47 +00:00
|
|
|
deps.diagnostics = bootstrapInfoWriter{reporter: invocation.Reporter()}
|
2026-11-20 05:59:09 +00:00
|
|
|
return deps
|
|
|
|
|
}
|
2026-11-20 06:32:47 +00:00
|
|
|
|
|
|
|
|
type bootstrapInfoWriter struct{ reporter *commandkit.Reporter }
|
|
|
|
|
|
|
|
|
|
func (w bootstrapInfoWriter) Write(body []byte) (int, error) {
|
|
|
|
|
_ = w.reporter.Info("", func(destination io.Writer) error { _, err := destination.Write(body); return err })
|
|
|
|
|
return len(body), nil
|
|
|
|
|
}
|