60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package cli
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"go.maximumdirect.net/ckconfig"
|
|
"go.maximumdirect.net/commandkit"
|
|
"go.maximumdirect.net/configkit"
|
|
)
|
|
|
|
type applicationAcquisition struct {
|
|
sources []configkit.SourceInfo
|
|
records []configkit.Diagnostic
|
|
err error
|
|
}
|
|
|
|
// acquisitionState holds only presentation evidence for this invocation, never
|
|
// configuration or engines. Each reached loader still performs a fresh load.
|
|
type acquisitionState struct{ applications []applicationAcquisition }
|
|
|
|
// Native PromptKit adapters interpret a ConfigKit LoadError as framework
|
|
// evidence. Transport application acquisition failure separately so it cannot
|
|
// become a finding in the framework view. The callback decorator restores the
|
|
// original typed cause before the native command classifies the outcome.
|
|
var errApplicationAcquisition = errors.New("application configuration acquisition failed")
|
|
|
|
func (state *acquisitionState) mark() int {
|
|
if state == nil {
|
|
return 0
|
|
}
|
|
return len(state.applications)
|
|
}
|
|
|
|
func attachApplicationEvidence[T any](acquired commandkit.Acquired[T], err error, state *acquisitionState, start int, comparison bool) (commandkit.Acquired[T], error) {
|
|
if state == nil {
|
|
return acquired, err
|
|
}
|
|
for index, application := range state.applications[start:] {
|
|
context := "Application configuration"
|
|
if comparison {
|
|
side := "left"
|
|
if index > 0 {
|
|
side = "right"
|
|
}
|
|
context += " (" + side + ")"
|
|
}
|
|
diagnostics, explanation := ckconfig.AdaptDiagnostics(context+":\n", application.sources, application.records)
|
|
acquired.Diagnostics = append(acquired.Diagnostics, diagnostics...)
|
|
if acquired.Explanation.Message == "" {
|
|
acquired.Explanation.Message = explanation.Message
|
|
}
|
|
acquired.Explanation.Details = append(acquired.Explanation.Details, explanation.Details...)
|
|
if application.err != nil && errors.Is(err, errApplicationAcquisition) {
|
|
err = fmt.Errorf("%s: %w", context, application.err)
|
|
}
|
|
}
|
|
return acquired, err
|
|
}
|