Reconstruct and merge ordered inputs without general sorting
This commit is contained in:
17
binding.go
17
binding.go
@@ -3,7 +3,6 @@ package commandkit
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
commandmeta "go.maximumdirect.net/commandkit/internal/commandmeta"
|
||||
@@ -298,7 +297,14 @@ func prepareInputWithOccurrences[I any](spec CommandSpec[I], flagValues, flagSpe
|
||||
fallbackOrdinal++
|
||||
}
|
||||
if occurrence.apply != nil {
|
||||
ordered = append(ordered, occurrence)
|
||||
if occurrences == nil {
|
||||
ordered = append(ordered, occurrence)
|
||||
} else {
|
||||
if ordered == nil {
|
||||
ordered = make([]preparedOccurrence[I], len(occurrences))
|
||||
}
|
||||
ordered[*occurrence.ordinal] = occurrence
|
||||
}
|
||||
}
|
||||
}
|
||||
if enforceRequired && binding.meta.Required && !binding.deferredRequired && !value.supplied && missingRequired == "" {
|
||||
@@ -313,9 +319,12 @@ func prepareInputWithOccurrences[I any](spec CommandSpec[I], flagValues, flagSpe
|
||||
return preparedInput[I]{}, err
|
||||
}
|
||||
preparedValues := append([]preparedValue[I](nil), preparedFlags...)
|
||||
sort.SliceStable(ordered, func(i, j int) bool { return *ordered[i].ordinal < *ordered[j].ordinal })
|
||||
// Parsed occurrences use dense parser positions; without a parser log the
|
||||
// fallback ordinals were assigned in the same order as the append above.
|
||||
for _, occurrence := range ordered {
|
||||
preparedValues = append(preparedValues, preparedValue[I]{apply: occurrence.apply})
|
||||
if occurrence.apply != nil {
|
||||
preparedValues = append(preparedValues, preparedValue[I]{apply: occurrence.apply})
|
||||
}
|
||||
}
|
||||
for i, argument := range spec.Arguments {
|
||||
binding := argument.binding
|
||||
|
||||
Reference in New Issue
Block a user