Parse invocation flags across command discovery

This commit is contained in:
2026-11-22 20:53:25 +00:00
parent ea3ce25001
commit b6cb183a71
10 changed files with 136 additions and 30 deletions

View File

@@ -45,6 +45,8 @@ func (a *App) Execute(ctx context.Context, args []string, streams Streams) Outco
handlerRan := false
if parsed.Failure != nil {
outcome = Usage(parsed.Failure.Message)
} else if err := current.prepareFeatures(parsed, !parsed.HelpRequested && current.route.kind == routeCanonical); err != nil {
outcome = classifyInputError(err)
} else if current.route.kind == routeDiscovery {
if parsed.HelpRequested {
outcome = current.renderHelp(parsed.Path)
@@ -77,14 +79,35 @@ func (a *App) Execute(ctx context.Context, args []string, streams Streams) Outco
return current.finalize(outcome, path, handlerRan)
}
func (current *execution) prepareFeatures(parsed commandmeta.Result, required bool) error {
if current.snapshot == nil {
return nil
}
offset := 0
for _, feature := range current.snapshot.features {
count := len(feature.payload.bridgeFlags())
if offset+count > len(parsed.InvocationFlagValues) || offset+count > len(parsed.InvocationFlagSpellings) {
return fmt.Errorf("missing invocation feature flag values")
}
start, err := feature.payload.prepare(parsed.InvocationFlagValues[offset:offset+count], parsed.InvocationFlagSpellings[offset:offset+count], parsed.FlagOccurrences, required)
if err != nil {
return err
}
current.featureStarts = append(current.featureStarts, start)
offset += count
}
return nil
}
type execution struct {
app *App
ctx context.Context
reporter *Reporter
debugEvents []string
snapshot *routingSnapshot
session *internalcobra.Session
route routeResult
app *App
ctx context.Context
reporter *Reporter
featureStarts []func(Invocation) (context.Context, func() Report)
debugEvents []string
snapshot *routingSnapshot
session *internalcobra.Session
route routeResult
}
type commandExecution struct {