Expose configuration metadata and findings
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
type scopeMetadata struct {
|
||||
Name string `json:"name"`
|
||||
Operations []Operation `json:"operations"`
|
||||
Features []string `json:"features,omitempty"`
|
||||
}
|
||||
|
||||
type scopeInventory struct {
|
||||
@@ -188,6 +189,7 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
|
||||
prepared.inventory.Scopes = append(prepared.inventory.Scopes, scopeMetadata{
|
||||
Name: scope.scope.Name,
|
||||
Operations: append([]Operation(nil), scope.scope.Operations...),
|
||||
Features: featureNames(scope.scope.Features),
|
||||
})
|
||||
}
|
||||
return prepared
|
||||
@@ -253,12 +255,32 @@ func joinNames(names []string) string {
|
||||
return strings.Join(ordered, ", ")
|
||||
}
|
||||
|
||||
var scopeInventoryTemplate = template.Must(commandkit.ParseTextTemplate("scopes", `{{range .Scopes}}{{.Name}}: {{range $index, $operation := .Operations}}{{if $index}}, {{end}}{{$operation}}{{end}}
|
||||
func featureNames(features ScopeFeatures) []string {
|
||||
var names []string
|
||||
if features.PathDiscovery {
|
||||
names = append(names, "path_discovery")
|
||||
}
|
||||
if features.PathShow {
|
||||
names = append(names, "path_show")
|
||||
}
|
||||
if features.Overrides {
|
||||
names = append(names, "overrides")
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
var scopeInventoryTemplate = template.Must(commandkit.ParseTextTemplate("scopes", `{{range .Scopes}}{{.Name}}: {{range $index, $operation := .Operations}}{{if $index}}, {{end}}{{$operation}}{{end}}{{if .Features}} (features: {{range $index, $feature := .Features}}{{if $index}}, {{end}}{{$feature}}{{end}}){{end}}
|
||||
{{end}}`, nil))
|
||||
|
||||
func newConfigScopesCommand[I, S any](prepared *preparedSuite[I, S]) commandkit.Command {
|
||||
var description strings.Builder
|
||||
for _, scope := range prepared.inventory.Scopes {
|
||||
if len(scope.Features) > 0 {
|
||||
fmt.Fprintf(&description, "%s: %s\n", scope.Name, strings.Join(scope.Features, ", "))
|
||||
}
|
||||
}
|
||||
return commandkit.NewCommand(commandkit.CommandSpec[struct{}]{
|
||||
Name: "scopes", Summary: "List configuration scopes and supported operations.",
|
||||
Name: "scopes", Summary: "List configuration scopes, operations, and supported features.", Description: description.String(),
|
||||
Run: func(invocation commandkit.Invocation, _ struct{}) commandkit.Outcome {
|
||||
_ = invocation.Reporter().Report(commandkit.Report{Value: prepared.inventory, TextTemplate: scopeInventoryTemplate})
|
||||
return commandkit.Success()
|
||||
|
||||
Reference in New Issue
Block a user