Separate configuration suite capture
This commit is contained in:
@@ -91,18 +91,16 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
|
||||
byName: make(map[string]*preparedScope[I, S], len(suite.Scopes)),
|
||||
bindingsByOperation: make(map[Operation][]commandkit.Flag[I]),
|
||||
}
|
||||
selectors := make([]Selector[I], len(suite.Selectors))
|
||||
against := make([]commandkit.Flag[I], len(suite.Selectors))
|
||||
for index, selector := range suite.Selectors {
|
||||
selector.Scopes = append([]string(nil), selector.Scopes...)
|
||||
selectors[index] = selector
|
||||
if selector.AgainstName != "" {
|
||||
against[index] = commandkit.RenameFlag(selector.Binding, selector.AgainstName)
|
||||
}
|
||||
}
|
||||
seenNames := captureConfigScopes(prepared, suite.Scopes)
|
||||
selectors, against := captureConfigSelectors(prepared, suite.Selectors, seenNames)
|
||||
captureOperationBindings(prepared, selectors, against)
|
||||
captureScopeInventory(prepared)
|
||||
return prepared
|
||||
}
|
||||
|
||||
seenNames := make(map[string]struct{}, len(suite.Scopes))
|
||||
for _, original := range suite.Scopes {
|
||||
func captureConfigScopes[I, S any](prepared *preparedSuite[I, S], scopes []Scope[I, S]) map[string]struct{} {
|
||||
seenNames := make(map[string]struct{}, len(scopes))
|
||||
for _, original := range scopes {
|
||||
scope := original
|
||||
scope.Operations = normalizeOperations(scope.Operations, &prepared.issues, scope.Name)
|
||||
scope.issues = append([]error(nil), original.issues...)
|
||||
@@ -146,6 +144,20 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
|
||||
}
|
||||
prepared.scopeChoices = joinNames(names)
|
||||
|
||||
return seenNames
|
||||
}
|
||||
|
||||
func captureConfigSelectors[I, S any](prepared *preparedSuite[I, S], originals []Selector[I], seenNames map[string]struct{}) ([]Selector[I], []commandkit.Flag[I]) {
|
||||
selectors := make([]Selector[I], len(originals))
|
||||
against := make([]commandkit.Flag[I], len(originals))
|
||||
for index, selector := range originals {
|
||||
selector.Scopes = append([]string(nil), selector.Scopes...)
|
||||
selectors[index] = selector
|
||||
if selector.AgainstName != "" {
|
||||
against[index] = commandkit.RenameFlag(selector.Binding, selector.AgainstName)
|
||||
}
|
||||
}
|
||||
|
||||
for index, selector := range selectors {
|
||||
seen := make(map[string]struct{}, len(selector.Scopes))
|
||||
uniqueScopes := make([]string, 0, len(selector.Scopes))
|
||||
@@ -181,6 +193,10 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
|
||||
}
|
||||
}
|
||||
|
||||
return selectors, against
|
||||
}
|
||||
|
||||
func captureOperationBindings[I, S any](prepared *preparedSuite[I, S], selectors []Selector[I], against []commandkit.Flag[I]) {
|
||||
for _, operation := range []Operation{Validate, Show, Sources, Explain, Diff} {
|
||||
for _, scope := range prepared.scopes {
|
||||
if containsOperation(scope.scope.Operations, operation) {
|
||||
@@ -200,6 +216,9 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func captureScopeInventory[I, S any](prepared *preparedSuite[I, S]) {
|
||||
for _, scope := range prepared.scopes {
|
||||
prepared.inventory.Scopes = append(prepared.inventory.Scopes, scopeMetadata{
|
||||
Name: scope.scope.Name,
|
||||
@@ -207,7 +226,6 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
|
||||
Features: featureNames(scope.scope.Features),
|
||||
})
|
||||
}
|
||||
return prepared
|
||||
}
|
||||
|
||||
func normalizeOperations(operations []Operation, issues *[]error, scope string) []Operation {
|
||||
|
||||
Reference in New Issue
Block a user