Initial cut

This commit is contained in:
Naveen Gogineni
2022-09-20 08:01:14 -04:00
parent f37b9d9b60
commit d5947d7814
8 changed files with 243 additions and 379 deletions
+9 -12
View File
@@ -230,13 +230,11 @@ func ShowCommandHelpAndExit(c *Context, command string, code int) {
// ShowCommandHelp prints help for the given command
func ShowCommandHelp(ctx *Context, command string) error {
// show the subcommand help for a command with subcommands
if command == "" {
HelpPrinter(ctx.App.Writer, SubcommandHelpTemplate, ctx.App)
return nil
commands := ctx.App.Commands
if ctx.Command != nil {
commands = ctx.Command.Subcommands
}
for _, c := range ctx.App.Commands {
for _, c := range commands {
if c.HasName(command) {
if !ctx.App.HideHelpCommand && !c.HasName(helpName) && len(c.Subcommands) != 0 {
c.Subcommands = append(c.Subcommands, helpCommandDontUse)
@@ -262,7 +260,7 @@ func ShowCommandHelp(ctx *Context, command string) error {
if ctx.App.CommandNotFound == nil {
errMsg := fmt.Sprintf("No help topic for '%v'", command)
if ctx.App.Suggest {
if suggestion := SuggestCommand(ctx.App.Commands, command); suggestion != "" {
if suggestion := SuggestCommand(ctx.Command.Subcommands, command); suggestion != "" {
errMsg += ". " + suggestion
}
}
@@ -285,11 +283,8 @@ func ShowSubcommandHelp(cCtx *Context) error {
return nil
}
if cCtx.Command != nil {
return ShowCommandHelp(cCtx, cCtx.Command.Name)
}
return ShowCommandHelp(cCtx, "")
HelpPrinter(cCtx.App.Writer, SubcommandHelpTemplate, cCtx.Command)
return nil
}
// ShowVersion prints the version number of the App
@@ -401,8 +396,10 @@ func checkHelp(cCtx *Context) bool {
for _, name := range HelpFlag.Names() {
if cCtx.Bool(name) {
found = true
break
}
}
return found
}