Route executions through neutral snapshots
This commit is contained in:
30
builtins.go
30
builtins.go
@@ -6,9 +6,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
internalcobra "gitea.maximumdirect.net/eric/CommandKit/internal/cobra"
|
||||
commandmeta "gitea.maximumdirect.net/eric/CommandKit/internal/commandmeta"
|
||||
yaml "go.yaml.in/yaml/v4"
|
||||
)
|
||||
|
||||
@@ -79,31 +79,25 @@ func parseVersionFormat(value string) (string, error) {
|
||||
}
|
||||
|
||||
func (a *App) renderHelpOutcome(path []string, streams Streams) Outcome {
|
||||
session := internalcobra.Prepare(a.bridgeTree(), internalcobra.ParseOptions{})
|
||||
session := internalcobra.Prepare(a.routeSnapshot().metadata, commandmeta.ParseOptions{})
|
||||
return a.renderHelpOutcomeWithSession(path, streams, session)
|
||||
}
|
||||
|
||||
func (a *App) renderHelpTargets(targets []string, streams Streams) Outcome {
|
||||
session := internalcobra.Prepare(a.bridgeTree(), internalcobra.ParseOptions{})
|
||||
session := internalcobra.Prepare(a.routeSnapshot().metadata, commandmeta.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)
|
||||
return a.renderHelpOutcomeWithSession(targets, 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 := session.RenderHelp(path)
|
||||
if failure != nil {
|
||||
if failure.Usage {
|
||||
return Usage(errors.New(failure.Message))
|
||||
}
|
||||
return Failure(errors.New(failure.Message))
|
||||
}
|
||||
if err := writeReport(streams.Out, []byte(content)); err != nil {
|
||||
@@ -201,13 +195,3 @@ func commandKitBuildIdentity(info *debug.BuildInfo) Identity {
|
||||
}
|
||||
return identity
|
||||
}
|
||||
|
||||
func (a *App) helpCommandTarget(targets []string) ([]string, error) {
|
||||
if len(targets) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if _, ok := a.commandAt(targets); !ok {
|
||||
return nil, fmt.Errorf("unknown help path %q", strings.Join(targets, " "))
|
||||
}
|
||||
return append([]string(nil), targets...), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user