Merge latest and fix tests

main
Naveen Gogineni 2 years ago
parent d5947d7814
commit bc9ae33465

@ -273,12 +273,12 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
cCtx.shellComplete = shellComplete
a.rootCommand = &Command{
HelpName: a.HelpName,
Subcommands: a.Commands,
flagCategories: a.flagCategories,
Flags: a.Flags,
Name: a.Name,
//Action: a.Action, // dont set this now
HelpName: a.HelpName,
Subcommands: a.Commands,
flagCategories: a.flagCategories,
Flags: a.Flags,
Name: a.Name,
Action: a.Action,
UseShortOptionHandling: a.UseShortOptionHandling,
Before: a.Before,
After: a.After,

@ -109,19 +109,14 @@ func (cmd *Command) Command(name string) *Command {
}
func (c *Command) setup(ctx *Context) {
helpCmd := helpCommand
if len(c.Subcommands) > 0 {
helpCmd = helpSubcommand
}
if c.Command(helpCmd.Name) == nil && !c.HideHelp {
if c.Command(helpCommand.Name) == nil && !c.HideHelp {
if !c.HideHelpCommand {
c.Subcommands = append(c.Subcommands, helpCmd)
c.Subcommands = append(c.Subcommands, helpCommand)
}
}
if c.helpAction == nil {
c.helpAction = helpCmd.Action
c.helpAction = helpCommand.Action
}
if !c.HideHelp && HelpFlag != nil {
@ -183,7 +178,7 @@ func (c *Command) Run(cCtx *Context, arguments []string) (err error) {
if c.isRoot {
_ = ShowAppHelp(cCtx)
} else {
_ = ShowCommandHelp(cCtx, c.Name)
_ = ShowCommandHelp(cCtx.parentContext, c.Name)
}
}
return err

@ -40,6 +40,7 @@ func TestCommandFlagParsing(t *testing.T) {
Description: "testing",
Action: func(_ *Context) error { return nil },
SkipFlagParsing: c.skipFlagParsing,
isRoot: true,
}
err := command.Run(cCtx, c.testArgs)

@ -68,6 +68,15 @@ var helpCommand = &Command{
}
// Case 3, 5
if (len(cCtx.Command.Subcommands) == 1 && !cCtx.Command.HideHelp) ||
(len(cCtx.Command.Subcommands) == 0 && cCtx.Command.HideHelp) {
templ := cCtx.Command.CustomHelpTemplate
if templ == "" {
templ = CommandHelpTemplate
}
HelpPrinter(cCtx.App.Writer, templ, cCtx.Command)
return nil
}
return ShowSubcommandHelp(cCtx)
},
}
@ -230,8 +239,9 @@ func ShowCommandHelpAndExit(c *Context, command string, code int) {
// ShowCommandHelp prints help for the given command
func ShowCommandHelp(ctx *Context, command string) error {
commands := ctx.App.Commands
if ctx.Command != nil {
if ctx.Command.Subcommands != nil {
commands = ctx.Command.Subcommands
}
for _, c := range commands {

Loading…
Cancel
Save