Changes from code review
This commit is contained in:
parent
59095aa762
commit
a9d6b0d821
27
app.go
27
app.go
@ -241,6 +241,31 @@ func (a *App) Setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) newRootCommand() *Command {
|
||||||
|
return &Command{
|
||||||
|
Name: a.Name,
|
||||||
|
Usage: a.Usage,
|
||||||
|
UsageText: a.UsageText,
|
||||||
|
Description: a.Description,
|
||||||
|
ArgsUsage: a.ArgsUsage,
|
||||||
|
BashComplete: a.BashComplete,
|
||||||
|
Before: a.Before,
|
||||||
|
After: a.After,
|
||||||
|
Action: a.Action,
|
||||||
|
OnUsageError: a.OnUsageError,
|
||||||
|
Subcommands: a.Commands,
|
||||||
|
Flags: a.Flags,
|
||||||
|
flagCategories: a.flagCategories,
|
||||||
|
HideHelp: a.HideHelp,
|
||||||
|
HideHelpCommand: a.HideHelpCommand,
|
||||||
|
UseShortOptionHandling: a.UseShortOptionHandling,
|
||||||
|
HelpName: a.HelpName,
|
||||||
|
CustomHelpTemplate: a.CustomAppHelpTemplate,
|
||||||
|
categories: a.categories,
|
||||||
|
isRoot: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) newFlagSet() (*flag.FlagSet, error) {
|
func (a *App) newFlagSet() (*flag.FlagSet, error) {
|
||||||
return flagSet(a.Name, a.Flags)
|
return flagSet(a.Name, a.Flags)
|
||||||
}
|
}
|
||||||
@ -272,7 +297,7 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
|
|||||||
cCtx := NewContext(a, nil, &Context{Context: ctx})
|
cCtx := NewContext(a, nil, &Context{Context: ctx})
|
||||||
cCtx.shellComplete = shellComplete
|
cCtx.shellComplete = shellComplete
|
||||||
|
|
||||||
a.rootCommand = newRootCommand(a)
|
a.rootCommand = a.newRootCommand()
|
||||||
cCtx.Command = a.rootCommand
|
cCtx.Command = a.rootCommand
|
||||||
|
|
||||||
return a.rootCommand.Run(cCtx, arguments...)
|
return a.rootCommand.Run(cCtx, arguments...)
|
||||||
|
@ -1901,6 +1901,7 @@ func TestApp_Run_CommandHelpName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
cmd := &Command{
|
cmd := &Command{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
HelpName: "custom",
|
||||||
Description: "foo commands",
|
Description: "foo commands",
|
||||||
Subcommands: []*Command{subCmd},
|
Subcommands: []*Command{subCmd},
|
||||||
}
|
}
|
||||||
|
29
command.go
29
command.go
@ -106,32 +106,11 @@ func (cmd *Command) Command(name string) *Command {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRootCommand(a *App) *Command {
|
|
||||||
return &Command{
|
|
||||||
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,
|
|
||||||
HideHelp: a.HideHelp,
|
|
||||||
HideHelpCommand: a.HideHelpCommand,
|
|
||||||
OnUsageError: a.OnUsageError,
|
|
||||||
CustomHelpTemplate: a.CustomAppHelpTemplate,
|
|
||||||
Usage: a.Usage,
|
|
||||||
UsageText: a.UsageText,
|
|
||||||
Description: a.Description,
|
|
||||||
ArgsUsage: a.ArgsUsage,
|
|
||||||
BashComplete: a.BashComplete,
|
|
||||||
categories: a.categories,
|
|
||||||
isRoot: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Command) setup(ctx *Context) {
|
func (c *Command) setup(ctx *Context) {
|
||||||
|
if c.HelpName == "" {
|
||||||
|
c.HelpName = fmt.Sprintf("%s %s", ctx.parentContext.Command.HelpName, c.Name)
|
||||||
|
}
|
||||||
|
|
||||||
if c.Command(helpCommand.Name) == nil && !c.HideHelp {
|
if c.Command(helpCommand.Name) == nil && !c.HideHelp {
|
||||||
if !c.HideHelpCommand {
|
if !c.HideHelpCommand {
|
||||||
c.Subcommands = append(c.Subcommands, helpCommand)
|
c.Subcommands = append(c.Subcommands, helpCommand)
|
||||||
|
Loading…
Reference in New Issue
Block a user