Skip to content

Commit

Permalink
Fix how to do defaults in app.go
Browse files Browse the repository at this point in the history
  • Loading branch information
phinnaeus authored and Tyler Davis committed Jun 28, 2017
1 parent 827da61 commit 80b09a4
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func NewApp() *App {
Action: helpCommand.Action,
Compiled: compileTime(),
Writer: os.Stdout,
ExitErrHandler: HandleExitCoder,
}
}

Expand Down Expand Up @@ -210,7 +211,7 @@ func (a *App) Run(arguments []string) (err error) {
if err != nil {
if a.OnUsageError != nil {
err := a.OnUsageError(context, err, false)
a.handleExitCoder(err)
a.ExitErrHandler(err)
return err
}
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
Expand Down Expand Up @@ -244,7 +245,7 @@ func (a *App) Run(arguments []string) (err error) {
beforeErr := a.Before(context)
if beforeErr != nil {
ShowAppHelp(context)
a.handleExitCoder(beforeErr)
a.ExitErrHandler(beforeErr)
err = beforeErr
return err
}
Expand All @@ -266,7 +267,7 @@ func (a *App) Run(arguments []string) (err error) {
// Run default Action
err = HandleAction(a.Action, context)

a.handleExitCoder(err)
a.ExitErrHandler(err)
return err
}

Expand Down Expand Up @@ -333,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.handleExitCoder(err)
a.ExitErrHandler(err)
return err
}
fmt.Fprintf(a.Writer, "%s %s\n\n", "Incorrect Usage.", err.Error())
Expand All @@ -355,7 +356,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
defer func() {
afterErr := a.After(context)
if afterErr != nil {
a.handleExitCoder(err)
a.ExitErrHandler(err)
if err != nil {
err = NewMultiError(err, afterErr)
} else {
Expand All @@ -368,7 +369,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
if a.Before != nil {
beforeErr := a.Before(context)
if beforeErr != nil {
a.handleExitCoder(beforeErr)
a.ExitErrHandler(beforeErr)
err = beforeErr
return err
}
Expand All @@ -386,7 +387,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
// Run default Action
err = HandleAction(a.Action, context)

a.handleExitCoder(err)
a.ExitErrHandler(err)
return err
}

Expand Down Expand Up @@ -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.
type Author struct {
Name string // The Authors name
Expand Down

0 comments on commit 80b09a4

Please sign in to comment.