Prepare configuration scope metadata

This commit is contained in:
2026-10-09 01:46:19 +00:00
parent a7960e5e94
commit 62b4a48e4f
8 changed files with 242 additions and 105 deletions

16
show.go
View File

@@ -8,17 +8,17 @@ import (
"unicode"
)
func newConfigShowCommand[C any](suite ConfigSuite[C]) (Command, error) {
func newConfigShowCommand[C any](prepared *preparedConfigSuite[C]) (Command, error) {
spec := CommandSpec[configInput[C]]{
Name: string(ConfigShow),
Summary: "Show effective configuration as YAML.",
Flags: configInputFlags(suite, "yaml"),
Flags: configInputFlags(prepared.suite, "yaml"),
CheckInput: func(input configInput[C]) error {
_, err := preflightConfig(suite, input, ConfigShow)
_, err := preflightConfig(prepared, input, ConfigShow)
return err
},
Run: func(invocation Invocation, input configInput[C]) Outcome {
return runConfigShow(invocation, suite, input)
return runConfigShow(invocation, prepared, input)
},
}
return NewCommand(spec)
@@ -29,19 +29,19 @@ type effectiveDocument struct {
view ConfigView
}
func runConfigShow[C any](invocation Invocation, suite ConfigSuite[C], input configInput[C]) Outcome {
func runConfigShow[C any](invocation Invocation, prepared *preparedConfigSuite[C], input configInput[C]) Outcome {
if err := invocation.Context.Err(); err != nil {
return Failure(err)
}
scopeNames, err := selectConfigScopes(suite, input, ConfigShow)
scopeNames, err := selectConfigScopes(prepared, input, ConfigShow)
if err != nil {
return Failure(err)
}
contexts := contextsForScopes(suite, input, scopeNames)
contexts := contextsForScopes(prepared, input, scopeNames)
documents := make([]effectiveDocument, 0, len(scopeNames))
diagnostics := make([]Diagnostic, 0)
for _, name := range scopeNames {
scope, ok := findConfigScope(suite.Scopes, name)
scope, ok := findConfigScope(prepared, name)
if !ok || scope.Acquire == nil {
return showFailure(fmt.Errorf("configuration scope %q has no acquisition callback", name), diagnostics, false)
}