Reuse adapter sessions during execution
This commit is contained in:
26
builtins.go
26
builtins.go
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user