Revert "Fix how to do defaults in app.go"
This reverts commit 8906567dc2ad52fd31c50cf02fa606505a1323ba.
This commit is contained in:
parent
80b09a4d11
commit
ceee6408d5
24
app.go
24
app.go
@ -121,7 +121,6 @@ func NewApp() *App {
|
|||||||
Action: helpCommand.Action,
|
Action: helpCommand.Action,
|
||||||
Compiled: compileTime(),
|
Compiled: compileTime(),
|
||||||
Writer: os.Stdout,
|
Writer: os.Stdout,
|
||||||
ExitErrHandler: HandleExitCoder,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +210,7 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if a.OnUsageError != nil {
|
if a.OnUsageError != nil {
|
||||||
err := a.OnUsageError(context, err, false)
|
err := a.OnUsageError(context, err, false)
|
||||||
a.ExitErrHandler(err)
|
a.handleExitCoder(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
||||||
@ -244,8 +243,9 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
if a.Before != nil {
|
if a.Before != nil {
|
||||||
beforeErr := a.Before(context)
|
beforeErr := a.Before(context)
|
||||||
if beforeErr != nil {
|
if beforeErr != nil {
|
||||||
|
fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
|
||||||
ShowAppHelp(context)
|
ShowAppHelp(context)
|
||||||
a.ExitErrHandler(beforeErr)
|
a.handleExitCoder(beforeErr)
|
||||||
err = beforeErr
|
err = beforeErr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -267,7 +267,7 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
// Run default Action
|
// Run default Action
|
||||||
err = HandleAction(a.Action, context)
|
err = HandleAction(a.Action, context)
|
||||||
|
|
||||||
a.ExitErrHandler(err)
|
a.handleExitCoder(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,7 +334,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if a.OnUsageError != nil {
|
if a.OnUsageError != nil {
|
||||||
err = a.OnUsageError(context, err, true)
|
err = a.OnUsageError(context, err, true)
|
||||||
a.ExitErrHandler(err)
|
a.handleExitCoder(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
|
||||||
@ -356,7 +356,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
afterErr := a.After(context)
|
afterErr := a.After(context)
|
||||||
if afterErr != nil {
|
if afterErr != nil {
|
||||||
a.ExitErrHandler(err)
|
a.handleExitCoder(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = NewMultiError(err, afterErr)
|
err = NewMultiError(err, afterErr)
|
||||||
} else {
|
} else {
|
||||||
@ -369,7 +369,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
if a.Before != nil {
|
if a.Before != nil {
|
||||||
beforeErr := a.Before(context)
|
beforeErr := a.Before(context)
|
||||||
if beforeErr != nil {
|
if beforeErr != nil {
|
||||||
a.ExitErrHandler(beforeErr)
|
a.handleExitCoder(beforeErr)
|
||||||
err = beforeErr
|
err = beforeErr
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -387,7 +387,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
|
|||||||
// Run default Action
|
// Run default Action
|
||||||
err = HandleAction(a.Action, context)
|
err = HandleAction(a.Action, context)
|
||||||
|
|
||||||
a.ExitErrHandler(err)
|
a.handleExitCoder(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,6 +468,14 @@ func (a *App) appendFlag(flag Flag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) handleExitCoder(err error) {
|
||||||
|
if a.ExitErrHandler != nil {
|
||||||
|
a.ExitErrHandler(err)
|
||||||
|
} else {
|
||||||
|
HandleExitCoder(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Author represents someone who has contributed to a cli project.
|
// Author represents someone who has contributed to a cli project.
|
||||||
type Author struct {
|
type Author struct {
|
||||||
Name string // The Authors name
|
Name string // The Authors name
|
||||||
|
Loading…
Reference in New Issue
Block a user