Reuse adapter sessions during execution

This commit is contained in:
2026-10-09 01:42:03 +00:00
parent a852301801
commit a7960e5e94
6 changed files with 328 additions and 32 deletions

View File

@@ -38,11 +38,7 @@ func (a *App) installBuiltins() error {
func(value string) (string, error) { return value, nil },
func(input *helpInput, value Supplied[[]string]) { input.Targets = value })},
Run: func(invocation Invocation, input helpInput) Outcome {
target, err := a.helpCommandTarget(input.Targets.Value)
if err != nil {
return Usage(err)
}
return a.renderHelpOutcome(target, invocation.Streams)
return a.renderHelpTargets(input.Targets.Value, invocation.Streams)
},
})
if err != nil {
@@ -92,12 +88,30 @@ func parseVersionFormat(value string) (string, error) {
}
func (a *App) renderHelpOutcome(path []string, streams Streams) Outcome {
session := internalcobra.Prepare(a.bridgeTree(), internalcobra.ParseOptions{})
return a.renderHelpOutcomeWithSession(path, streams, session)
}
func (a *App) renderHelpTargets(targets []string, streams Streams) Outcome {
session := internalcobra.Prepare(a.bridgeTree(), internalcobra.ParseOptions{})
return a.renderHelpTargetsWithSession(targets, streams, session)
}
func (a *App) renderHelpTargetsWithSession(targets []string, streams Streams, session *internalcobra.Session) Outcome {
target, err := a.helpCommandTarget(targets)
if err != nil {
return Usage(err)
}
return a.renderHelpOutcomeWithSession(target, streams, session)
}
func (a *App) renderHelpOutcomeWithSession(path []string, streams Streams, session *internalcobra.Session) Outcome {
if len(path) > 0 {
if _, ok := a.commandAt(path); !ok {
return Usage(fmt.Errorf("unknown help path %q", strings.Join(path, " ")))
}
}
content, failure := internalcobra.RenderHelp(a.bridgeTree(), path)
content, failure := session.RenderHelp(path)
if failure != nil {
return Failure(errors.New(failure.Message))
}