Port native configuration reports
This commit is contained in:
47
integrations/ckconfig/operations.go
Normal file
47
integrations/ckconfig/operations.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package ckconfig
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
commandkit "gitea.maximumdirect.net/eric/CommandKit"
|
||||
)
|
||||
|
||||
func runConfigOperation[I, S any](invocation commandkit.Invocation, operation Operation, input *configCommandInput[I, S]) commandkit.Outcome {
|
||||
if input == nil || input.plan == nil {
|
||||
return commandkit.Failure(errors.New("configuration operation was not prepared"))
|
||||
}
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return commandkit.Failure(err)
|
||||
}
|
||||
plan := input.plan
|
||||
var state S
|
||||
if plan.prepared.newState != nil {
|
||||
state = plan.prepared.newState()
|
||||
}
|
||||
switch operation {
|
||||
case Validate:
|
||||
return runConfigValidation(invocation, plan, state)
|
||||
case Show:
|
||||
return runConfigShow(invocation, plan, state)
|
||||
case Sources:
|
||||
return runConfigSources(invocation, plan, state)
|
||||
case Explain:
|
||||
return runConfigExplanation(invocation, plan, state)
|
||||
default:
|
||||
return commandkit.Failure(fmt.Errorf("unsupported configuration operation %q", operation))
|
||||
}
|
||||
}
|
||||
|
||||
func configOperationFailure(cause error, diagnostics []commandkit.Diagnostic, reportStarted bool) commandkit.Outcome {
|
||||
outcome := commandkit.Failure(cause)
|
||||
outcome.Diagnostics = diagnostics
|
||||
outcome.ReportIncomplete = reportStarted
|
||||
return outcome
|
||||
}
|
||||
|
||||
func configDeliveryFailure(cause error, diagnostics []commandkit.Diagnostic, reportStarted bool) commandkit.Outcome {
|
||||
outcome := configOperationFailure(cause, diagnostics, reportStarted)
|
||||
outcome.DeliveryError = cause
|
||||
return outcome
|
||||
}
|
||||
Reference in New Issue
Block a user