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 := NewContext(a, nil, &Context{Context: ctx})
|
||||||
cCtx.shellComplete = shellComplete
|
cCtx.shellComplete = shellComplete
|
||||||
|
|
||||||
a.rootCommand = &Command{
|
a.rootCommand = newRootCommand(a)
|
||||||
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,
|
|
||||||
}
|
|
||||||
cCtx.Command = a.rootCommand
|
cCtx.Command = a.rootCommand
|
||||||
|
|
||||||
return a.rootCommand.Run(cCtx, arguments)
|
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
|
// if this is a root "special" command
|
||||||
isRoot bool
|
isRoot bool
|
||||||
|
|
||||||
helpAction ActionFunc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Commands []*Command
|
type Commands []*Command
|
||||||
@ -108,6 +106,31 @@ 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.Command(helpCommand.Name) == nil && !c.HideHelp {
|
if c.Command(helpCommand.Name) == nil && !c.HideHelp {
|
||||||
if !c.HideHelpCommand {
|
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 {
|
if !c.HideHelp && HelpFlag != nil {
|
||||||
// append help to flags
|
// append help to flags
|
||||||
c.appendFlag(HelpFlag)
|
c.appendFlag(HelpFlag)
|
||||||
@ -185,11 +204,7 @@ func (c *Command) Run(cCtx *Context, arguments []string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if checkHelp(cCtx) {
|
if checkHelp(cCtx) {
|
||||||
return c.helpAction(cCtx)
|
return helpCommand.Action(cCtx)
|
||||||
}
|
|
||||||
|
|
||||||
if cCtx.Args().First() == "help" && c.Action == nil {
|
|
||||||
return c.helpAction(cCtx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.isRoot && !cCtx.App.HideVersion && checkVersion(cCtx) {
|
if c.isRoot && !cCtx.App.HideVersion && checkVersion(cCtx) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user