Cleanup
This commit is contained in:
parent
00ef229486
commit
2047c6630c
24
app.go
24
app.go
@ -272,29 +272,7 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
|
||||
cCtx := NewContext(a, nil, &Context{Context: ctx})
|
||||
cCtx.shellComplete = shellComplete
|
||||
|
||||
a.rootCommand = &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,
|
||||
helpAction: helpCommand.Action,
|
||||
isRoot: true,
|
||||
}
|
||||
a.rootCommand = newRootCommand(a)
|
||||
cCtx.Command = a.rootCommand
|
||||
|
||||
return a.rootCommand.Run(cCtx, arguments)
|
||||
|
37
command.go
37
command.go
@ -69,8 +69,6 @@ type Command struct {
|
||||
|
||||
// if this is a root "special" command
|
||||
isRoot bool
|
||||
|
||||
helpAction ActionFunc
|
||||
}
|
||||
|
||||
type Commands []*Command
|
||||
@ -108,6 +106,31 @@ func (cmd *Command) Command(name string) *Command {
|
||||
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) {
|
||||
if c.Command(helpCommand.Name) == nil && !c.HideHelp {
|
||||
if !c.HideHelpCommand {
|
||||
@ -115,10 +138,6 @@ func (c *Command) setup(ctx *Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if c.helpAction == nil {
|
||||
c.helpAction = helpCommand.Action
|
||||
}
|
||||
|
||||
if !c.HideHelp && HelpFlag != nil {
|
||||
// append help to flags
|
||||
c.appendFlag(HelpFlag)
|
||||
@ -185,11 +204,7 @@ func (c *Command) Run(cCtx *Context, arguments []string) (err error) {
|
||||
}
|
||||
|
||||
if checkHelp(cCtx) {
|
||||
return c.helpAction(cCtx)
|
||||
}
|
||||
|
||||
if cCtx.Args().First() == "help" && c.Action == nil {
|
||||
return c.helpAction(cCtx)
|
||||
return helpCommand.Action(cCtx)
|
||||
}
|
||||
|
||||
if c.isRoot && !cCtx.App.HideVersion && checkVersion(cCtx) {
|
||||
|
Loading…
Reference in New Issue
Block a user