Render help through command aliases
This commit is contained in:
21
builtins.go
21
builtins.go
@@ -89,11 +89,28 @@ func (a *App) renderHelpTargets(targets []string, streams Streams) Outcome {
|
||||
}
|
||||
|
||||
func (a *App) renderHelpTargetsWithSession(targets []string, streams Streams, session *internalcobra.Session) Outcome {
|
||||
return a.renderHelpOutcomeWithSession(targets, streams, session)
|
||||
snapshot := a.routeSnapshot()
|
||||
route := resolveEnteredRoute(targets, snapshot)
|
||||
if route.kind == routeUnknown {
|
||||
return a.renderHelpOutcomeWithSession(targets, streams, session)
|
||||
}
|
||||
options := commandmeta.ParseOptions{}
|
||||
switch route.kind {
|
||||
case routeCanonical:
|
||||
options.FlagAliases = snapshot.flagAliases[route.canonicalPath.Key()].neutralRecords()
|
||||
case routeDiscovery:
|
||||
options.FlagAliases = snapshot.discoveryFlags[route.discoveryPath.Key()].neutralRecords()
|
||||
}
|
||||
session = internalcobra.Prepare(snapshot.metadata, options)
|
||||
return a.renderHelpViewOutcomeWithSession(a.helpView(route, snapshot), streams, session)
|
||||
}
|
||||
|
||||
func (a *App) renderHelpOutcomeWithSession(path []string, streams Streams, session *internalcobra.Session) Outcome {
|
||||
content, failure := session.RenderHelp(path)
|
||||
return a.renderHelpViewOutcomeWithSession(commandmeta.HelpView{EnteredPath: path, CanonicalPath: path}, streams, session)
|
||||
}
|
||||
|
||||
func (a *App) renderHelpViewOutcomeWithSession(view commandmeta.HelpView, streams Streams, session *internalcobra.Session) Outcome {
|
||||
content, failure := session.RenderHelpView(view)
|
||||
if failure != nil {
|
||||
if failure.Usage {
|
||||
return Usage(errors.New(failure.Message))
|
||||
|
||||
Reference in New Issue
Block a user