Fix how to do defaults in app.go

main
Tyler Davis 7 years ago committed by Tyler Davis
parent 827da610b4
commit 80b09a4d11

@ -121,6 +121,7 @@ func NewApp() *App {
Action: helpCommand.Action, Action: helpCommand.Action,
Compiled: compileTime(), Compiled: compileTime(),
Writer: os.Stdout, Writer: os.Stdout,
ExitErrHandler: HandleExitCoder,
} }
} }
@ -210,7 +211,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.handleExitCoder(err) a.ExitErrHandler(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,7 +245,7 @@ func (a *App) Run(arguments []string) (err error) {
beforeErr := a.Before(context) beforeErr := a.Before(context)
if beforeErr != nil { if beforeErr != nil {
ShowAppHelp(context) ShowAppHelp(context)
a.handleExitCoder(beforeErr) a.ExitErrHandler(beforeErr)
err = beforeErr err = beforeErr
return err return err
} }
@ -266,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.handleExitCoder(err) a.ExitErrHandler(err)
return err return err
} }
@ -333,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.handleExitCoder(err) a.ExitErrHandler(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())
@ -355,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.handleExitCoder(err) a.ExitErrHandler(err)
if err != nil { if err != nil {
err = NewMultiError(err, afterErr) err = NewMultiError(err, afterErr)
} else { } else {
@ -368,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.handleExitCoder(beforeErr) a.ExitErrHandler(beforeErr)
err = beforeErr err = beforeErr
return err return err
} }
@ -386,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.handleExitCoder(err) a.ExitErrHandler(err)
return err return err
} }
@ -467,14 +468,6 @@ 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…
Cancel
Save