Run invocation features and render final reports

This commit is contained in:
2026-11-22 20:54:58 +00:00
parent b6cb183a71
commit d039efb11d
9 changed files with 182 additions and 14 deletions

View File

@@ -72,6 +72,7 @@ func (a *App) Execute(ctx context.Context, args []string, streams Streams) Outco
outcome = classifyInputError(err)
} else {
handlerRan = true
current.featureEnabled = !routedSnapshot.builtins[parsed.Key]
outcome = run(current)
}
}
@@ -100,14 +101,31 @@ func (current *execution) prepareFeatures(parsed commandmeta.Result, required bo
}
type execution struct {
app *App
ctx context.Context
reporter *Reporter
featureStarts []func(Invocation) (context.Context, func() Report)
debugEvents []string
snapshot *routingSnapshot
session *internalcobra.Session
route routeResult
app *App
ctx context.Context
reporter *Reporter
featureStarts []func(Invocation) (context.Context, func() Report)
featureEnabled bool
featureReports []func() Report
debugEvents []string
snapshot *routingSnapshot
session *internalcobra.Session
route routeResult
}
func (current *execution) startFeatures() {
if !current.featureEnabled {
return
}
for _, start := range current.featureStarts {
ctx, report := start(current.invocation())
if ctx != nil {
current.ctx = ctx
}
if report != nil {
current.featureReports = append(current.featureReports, report)
}
}
}
type commandExecution struct {
@@ -363,7 +381,7 @@ func (current *execution) finalize(outcome Outcome, path []string, handlerRan bo
_ = reporter.Debug(fmt.Sprintf("handler completed for %q with %s outcome and status %d", path, kind, outcome.Status))
}
}
return current.reporter.finalize(outcome, completion)
return current.reporter.finalize(outcome, completion, current.featureReports...)
}
func (current *execution) usageText(path []string) string {