Capture immutable command declarations
This commit is contained in:
22
outcome.go
22
outcome.go
@@ -3,8 +3,16 @@ package commandkit
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
// Severity classifies a neutral diagnostic.
|
||||
type Severity string
|
||||
|
||||
const (
|
||||
// SeverityWarning indicates information that does not fail the operation.
|
||||
SeverityWarning Severity = "warning"
|
||||
// SeverityError indicates a diagnostic associated with an error.
|
||||
SeverityError Severity = "error"
|
||||
)
|
||||
|
||||
// OutcomeKind classifies the result of a command invocation.
|
||||
@@ -38,12 +46,18 @@ const (
|
||||
// Write is called by CommandKit's diagnostic delivery path. It should return
|
||||
// any error encountered while writing. A nil Write function has no output.
|
||||
type Diagnostic struct {
|
||||
// Severity classifies the diagnostic using ConfigKit's public severity type.
|
||||
Severity configkit.Severity
|
||||
// Severity classifies the diagnostic without depending on a provider library.
|
||||
Severity Severity
|
||||
// Write writes the diagnostic to the supplied writer.
|
||||
Write func(io.Writer) error
|
||||
}
|
||||
|
||||
// Acquired pairs a provider value with diagnostics emitted during acquisition.
|
||||
type Acquired[T any] struct {
|
||||
Value T
|
||||
Diagnostics []Diagnostic
|
||||
}
|
||||
|
||||
// Outcome is the classified result of an operation.
|
||||
//
|
||||
// Cause records the operation error. DeliveryError records an error encountered
|
||||
@@ -95,7 +109,7 @@ func Domain(name string, status int, cause error) Outcome {
|
||||
|
||||
// MessageDiagnostic returns a diagnostic that writes message followed by a
|
||||
// newline. The writer's error is returned to the caller.
|
||||
func MessageDiagnostic(severity configkit.Severity, message string) Diagnostic {
|
||||
func MessageDiagnostic(severity Severity, message string) Diagnostic {
|
||||
return Diagnostic{
|
||||
Severity: severity,
|
||||
Write: func(w io.Writer) error {
|
||||
|
||||
Reference in New Issue
Block a user