Separate comparison side selectors

This commit is contained in:
2026-11-07 04:36:05 +00:00
parent da120c2dd4
commit 85ae55bf42
15 changed files with 169 additions and 99 deletions

View File

@@ -23,8 +23,9 @@ type scopeInventory struct {
}
type preparedScope[I, S any] struct {
scope Scope[I, S]
bindings []commandkit.Flag[I]
scope Scope[I, S]
bindings []commandkit.Flag[I]
againstBindings []commandkit.Flag[I]
}
type preparedSuite[I, S any] struct {
@@ -34,6 +35,7 @@ type preparedSuite[I, S any] struct {
scopes []*preparedScope[I, S]
byName map[string]*preparedScope[I, S]
bindingsByOperation map[Operation][]commandkit.Flag[I]
againstBindings []commandkit.Flag[I]
scopeChoices string
operations []Operation
inventory scopeInventory
@@ -90,9 +92,13 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
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 := make(map[string]struct{}, len(suite.Scopes))
@@ -158,12 +164,18 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
for scopeIndex := range prepared.scopes {
if len(prepared.scopes[scopeIndex].scope.Operations) > 0 {
prepared.scopes[scopeIndex].bindings = append(prepared.scopes[scopeIndex].bindings, selector.Binding)
if selector.AgainstName != "" && containsOperation(prepared.scopes[scopeIndex].scope.Operations, Diff) {
prepared.scopes[scopeIndex].againstBindings = append(prepared.scopes[scopeIndex].againstBindings, against[index])
}
}
}
} else {
for _, name := range uniqueScopes {
if scope, exists := prepared.byName[name]; exists && len(scope.scope.Operations) > 0 {
scope.bindings = append(scope.bindings, selector.Binding)
if selector.AgainstName != "" && containsOperation(scope.scope.Operations, Diff) {
scope.againstBindings = append(scope.againstBindings, against[index])
}
}
}
}
@@ -176,10 +188,13 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
break
}
}
for _, selector := range selectors {
for index, selector := range selectors {
for _, scope := range prepared.scopes {
if containsOperation(scope.scope.Operations, operation) && selectorApplies(selector.Scopes, scope.scope.Name) {
prepared.bindingsByOperation[operation] = append(prepared.bindingsByOperation[operation], selector.Binding)
if operation == Diff && selector.AgainstName != "" {
prepared.againstBindings = append(prepared.againstBindings, against[index])
}
break
}
}