Revert "Fix how to do defaults in app.go"

This reverts commit 8906567dc2ad52fd31c50cf02fa606505a1323ba.
main
Tyler Davis 7 years ago
parent 80b09a4d11
commit ceee6408d5

@ -121,7 +121,6 @@ func NewApp() *App {
Action: helpCommand.Action,
Compiled: compileTime(),
Writer: os.Stdout,
ExitErrHandler: HandleExitCoder,
}
}
@ -211,7 +210,7 @@ func (a *App) Run(arguments []string) (err error) {
if err != nil {
if a.OnUsageError != nil {
err := a.OnUsageError(context, err, false)
a.ExitErrHandler(err)
a.handleExitCoder(err)
return err
}
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 {
beforeErr := a.Before(context)
if beforeErr != nil {
fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
ShowAppHelp(context)
a.ExitErrHandler(beforeErr)
a.handleExitCoder(beforeErr)
err = beforeErr
return err
}
@ -267,7 +267,7 @@ func (a *App) Run(arguments []string) (err error) {
// Run default Action
err = HandleAction(a.Action, context)
a.ExitErrHandler(err)
a.handleExitCoder(err)
return err
}
@ -334,7 +334,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
if err != nil {
if a.OnUsageError != nil {
err = a.OnUsageError(context, err, true)
a.ExitErrHandler(err)
a.handleExitCoder(err)
return err
}
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() {
afterErr := a.After(context)
if afterErr != nil {
a.ExitErrHandler(err)
a.handleExitCoder(err)
if err != nil {
err = NewMultiError(err, afterErr)
} else {
@ -369,7 +369,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
if a.Before != nil {
beforeErr := a.Before(context)
if beforeErr != nil {
a.ExitErrHandler(beforeErr)
a.handleExitCoder(beforeErr)
err = beforeErr
return err
}
@ -387,7 +387,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
// Run default Action
err = HandleAction(a.Action, context)
a.ExitErrHandler(err)
a.handleExitCoder(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.
type Author struct {
Name string // The Authors name

Loading…
Cancel
Save