Add focused configuration reports
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
commandkit "go.maximumdirect.net/commandkit"
|
||||
)
|
||||
@@ -31,6 +32,31 @@ func runConfigShow[I, S any](invocation commandkit.Invocation, plan *configOpera
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return configFailure("Configuration show was canceled.", acquired.Explanation, err)
|
||||
}
|
||||
if plan.pathSet {
|
||||
if acquired.Value.Explanation == nil {
|
||||
return configFailure("Configuration scope did not provide explanation data.", acquired.Explanation, fmt.Errorf("configuration scope %q declared path show without an explanation reader", selected.scope.scope.Name))
|
||||
}
|
||||
explanation, found := acquired.Value.Explanation.Explain(plan.path)
|
||||
if !found || !explanation.Effective.Present {
|
||||
return configFailure("The requested effective configuration path is not available.", acquired.Explanation, fmt.Errorf("configuration path %q is not effective in scope %q", plan.path.String(), selected.scope.scope.Name))
|
||||
}
|
||||
if err := invocation.Context.Err(); err != nil {
|
||||
return configFailure("Configuration show was canceled.", acquired.Explanation, err)
|
||||
}
|
||||
var value any
|
||||
err := reporter.RenderOutput(func(io.Writer) error {
|
||||
var err error
|
||||
value, err = commandkit.DecodeYAMLReport(strings.NewReader(explanation.Effective.YAML))
|
||||
return err
|
||||
})
|
||||
if err == nil {
|
||||
if canceled := invocation.Context.Err(); canceled != nil {
|
||||
return configFailure("Configuration show was canceled.", acquired.Explanation, canceled)
|
||||
}
|
||||
_ = reporter.Report(commandkit.Report{Value: value})
|
||||
}
|
||||
return commandkit.Success()
|
||||
}
|
||||
if acquired.Value.Effective == nil {
|
||||
return commandkit.Failure(fmt.Sprintf("Configuration scope %q did not provide an effective configuration writer.", selected.scope.scope.Name))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user