Route console diagnostics and stage progress through native reporting
This commit is contained in:
48
internal/app/command_reporting.go
Normal file
48
internal/app/command_reporting.go
Normal file
@@ -0,0 +1,48 @@
|
||||
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()}
|
||||
return deps
|
||||
}
|
||||
Reference in New Issue
Block a user