Preserve ordered flag occurrences

This commit is contained in:
2026-11-07 03:49:34 +00:00
parent d748056652
commit 7159f52f4d
6 changed files with 273 additions and 12 deletions

View File

@@ -127,6 +127,13 @@ type preparedValue[I any] struct {
identity *bindingIdentity
supplied bool
apply func(*I)
ordered []preparedOccurrence[I]
}
type preparedOccurrence[I any] struct {
// Captured bindings share this position with the outer prepared occurrence.
ordinal *int
apply func(*I)
}
type flagBinding[I any] struct {
@@ -186,7 +193,7 @@ type commandPayload interface {
hasRun() bool
bridgeFlags() []commandmeta.Flag
bridgeArguments() []commandmeta.Argument
prepare([][]string, [][]string, []string, bool) (func(*execution) Outcome, error)
prepare([][]string, [][]string, []commandmeta.FlagOccurrence, []string, bool) (func(*execution) Outcome, error)
}
type typedCommand[I any] struct {
@@ -235,8 +242,8 @@ func (c typedCommand[I]) bridgeArguments() []commandmeta.Argument {
return arguments
}
func (c typedCommand[I]) prepare(flagValues, flagSpellings [][]string, operands []string, enforceRequired bool) (func(*execution) Outcome, error) {
prepared, err := prepareInputWithSpellings(c.spec, flagValues, flagSpellings, operands, enforceRequired)
func (c typedCommand[I]) prepare(flagValues, flagSpellings [][]string, occurrences []commandmeta.FlagOccurrence, operands []string, enforceRequired bool) (func(*execution) Outcome, error) {
prepared, err := prepareInputWithOccurrences(c.spec, flagValues, flagSpellings, occurrences, operands, enforceRequired)
if err != nil {
return nil, err
}