Run invocation features and render final reports
This commit is contained in:
36
execute.go
36
execute.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user