Merge latest and fix tests
This commit is contained in:
parent
d5947d7814
commit
bc9ae33465
12
app.go
12
app.go
@ -273,12 +273,12 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
|
|||||||
cCtx.shellComplete = shellComplete
|
cCtx.shellComplete = shellComplete
|
||||||
|
|
||||||
a.rootCommand = &Command{
|
a.rootCommand = &Command{
|
||||||
HelpName: a.HelpName,
|
HelpName: a.HelpName,
|
||||||
Subcommands: a.Commands,
|
Subcommands: a.Commands,
|
||||||
flagCategories: a.flagCategories,
|
flagCategories: a.flagCategories,
|
||||||
Flags: a.Flags,
|
Flags: a.Flags,
|
||||||
Name: a.Name,
|
Name: a.Name,
|
||||||
//Action: a.Action, // dont set this now
|
Action: a.Action,
|
||||||
UseShortOptionHandling: a.UseShortOptionHandling,
|
UseShortOptionHandling: a.UseShortOptionHandling,
|
||||||
Before: a.Before,
|
Before: a.Before,
|
||||||
After: a.After,
|
After: a.After,
|
||||||
|
13
command.go
13
command.go
@ -109,19 +109,14 @@ func (cmd *Command) Command(name string) *Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) setup(ctx *Context) {
|
func (c *Command) setup(ctx *Context) {
|
||||||
helpCmd := helpCommand
|
if c.Command(helpCommand.Name) == nil && !c.HideHelp {
|
||||||
if len(c.Subcommands) > 0 {
|
|
||||||
helpCmd = helpSubcommand
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Command(helpCmd.Name) == nil && !c.HideHelp {
|
|
||||||
if !c.HideHelpCommand {
|
if !c.HideHelpCommand {
|
||||||
c.Subcommands = append(c.Subcommands, helpCmd)
|
c.Subcommands = append(c.Subcommands, helpCommand)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.helpAction == nil {
|
if c.helpAction == nil {
|
||||||
c.helpAction = helpCmd.Action
|
c.helpAction = helpCommand.Action
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.HideHelp && HelpFlag != nil {
|
if !c.HideHelp && HelpFlag != nil {
|
||||||
@ -183,7 +178,7 @@ func (c *Command) Run(cCtx *Context, arguments []string) (err error) {
|
|||||||
if c.isRoot {
|
if c.isRoot {
|
||||||
_ = ShowAppHelp(cCtx)
|
_ = ShowAppHelp(cCtx)
|
||||||
} else {
|
} else {
|
||||||
_ = ShowCommandHelp(cCtx, c.Name)
|
_ = ShowCommandHelp(cCtx.parentContext, c.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -40,6 +40,7 @@ func TestCommandFlagParsing(t *testing.T) {
|
|||||||
Description: "testing",
|
Description: "testing",
|
||||||
Action: func(_ *Context) error { return nil },
|
Action: func(_ *Context) error { return nil },
|
||||||
SkipFlagParsing: c.skipFlagParsing,
|
SkipFlagParsing: c.skipFlagParsing,
|
||||||
|
isRoot: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := command.Run(cCtx, c.testArgs)
|
err := command.Run(cCtx, c.testArgs)
|
||||||
|
12
help.go
12
help.go
@ -68,6 +68,15 @@ var helpCommand = &Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Case 3, 5
|
// 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)
|
return ShowSubcommandHelp(cCtx)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -230,8 +239,9 @@ func ShowCommandHelpAndExit(c *Context, command string, code int) {
|
|||||||
|
|
||||||
// ShowCommandHelp prints help for the given command
|
// ShowCommandHelp prints help for the given command
|
||||||
func ShowCommandHelp(ctx *Context, command string) error {
|
func ShowCommandHelp(ctx *Context, command string) error {
|
||||||
|
|
||||||
commands := ctx.App.Commands
|
commands := ctx.App.Commands
|
||||||
if ctx.Command != nil {
|
if ctx.Command.Subcommands != nil {
|
||||||
commands = ctx.Command.Subcommands
|
commands = ctx.Command.Subcommands
|
||||||
}
|
}
|
||||||
for _, c := range commands {
|
for _, c := range commands {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user