Pass context into handleExitCoder
This commit is contained in:
parent
9d61cbad02
commit
530df59178
18
app.go
18
app.go
@ -210,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.handleExitCoder(err)
|
a.handleExitCoder(context, 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())
|
||||||
@ -245,7 +245,7 @@ func (a *App) Run(arguments []string) (err error) {
|
|||||||
if beforeErr != nil {
|
if beforeErr != nil {
|
||||||
fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
|
fmt.Fprintf(a.Writer, "%v\n\n", beforeErr)
|
||||||
ShowAppHelp(context)
|
ShowAppHelp(context)
|
||||||
a.handleExitCoder(beforeErr)
|
a.handleExitCoder(context, 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.handleExitCoder(err)
|
a.handleExitCoder(context, 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.handleExitCoder(err)
|
a.handleExitCoder(context, 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.handleExitCoder(err)
|
a.handleExitCoder(context, 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.handleExitCoder(beforeErr)
|
a.handleExitCoder(context, 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.handleExitCoder(err)
|
a.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,9 +468,9 @@ func (a *App) appendFlag(flag Flag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) handleExitCoder(err error) {
|
func (a *App) handleExitCoder(context *Context, error) {
|
||||||
if a.ExitErrHandler != nil {
|
if a.ExitErrHandler != nil {
|
||||||
a.ExitErrHandler(err)
|
a.ExitErrHandler(context, err)
|
||||||
} else {
|
} else {
|
||||||
HandleExitCoder(err)
|
HandleExitCoder(err)
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if c.OnUsageError != nil {
|
if c.OnUsageError != nil {
|
||||||
err := c.OnUsageError(context, err, false)
|
err := c.OnUsageError(context, err, false)
|
||||||
context.App.handleExitCoder(err)
|
context.App.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error())
|
fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error())
|
||||||
@ -184,7 +184,7 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
afterErr := c.After(context)
|
afterErr := c.After(context)
|
||||||
if afterErr != nil {
|
if afterErr != nil {
|
||||||
ctx.App.handleExitCoder(err)
|
context.App.handleExitCoder(context, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = NewMultiError(err, afterErr)
|
err = NewMultiError(err, afterErr)
|
||||||
} else {
|
} else {
|
||||||
@ -198,7 +198,7 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
err = c.Before(context)
|
err = c.Before(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ShowCommandHelp(context, c.Name)
|
ShowCommandHelp(context, c.Name)
|
||||||
context.App.handleExitCoder(err)
|
context.App.handleExitCoder(context, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ func (c Command) Run(ctx *Context) (err error) {
|
|||||||
err = HandleAction(c.Action, context)
|
err = HandleAction(c.Action, context)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.App.handleExitCoder(err)
|
context.App.handleExitCoder(context, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
2
funcs.go
2
funcs.go
@ -29,4 +29,4 @@ type FlagStringFunc func(Flag) string
|
|||||||
|
|
||||||
// ExitErrHandlerFunc is executed if provided in order to handle ExitError values
|
// ExitErrHandlerFunc is executed if provided in order to handle ExitError values
|
||||||
// returned by Actions and Before/After functions.
|
// returned by Actions and Before/After functions.
|
||||||
type ExitErrHandlerFunc func(error)
|
type ExitErrHandlerFunc func(context *Context, error)
|
||||||
|
Loading…
Reference in New Issue
Block a user