Fix:(issue_1094) Dont execute Before/After handlers during shell completion

This commit is contained in:
Naveen Gogineni
2022-08-17 21:19:34 -04:00
parent 7357e10160
commit 57a8423422
2 changed files with 56 additions and 4 deletions

8
app.go
View File

@@ -304,7 +304,7 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
return err
}
if a.After != nil {
if a.After != nil && !cCtx.shellComplete {
defer func() {
if afterErr := a.After(cCtx); afterErr != nil {
if err != nil {
@@ -332,7 +332,7 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) {
return cerr
}
if a.Before != nil {
if a.Before != nil && !cCtx.shellComplete {
beforeErr := a.Before(cCtx)
if beforeErr != nil {
a.handleExitCoder(cCtx, beforeErr)
@@ -499,7 +499,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
return cerr
}
if a.After != nil {
if a.After != nil && !cCtx.shellComplete {
defer func() {
afterErr := a.After(cCtx)
if afterErr != nil {
@@ -513,7 +513,7 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) {
}()
}
if a.Before != nil {
if a.Before != nil && !cCtx.shellComplete {
beforeErr := a.Before(cCtx)
if beforeErr != nil {
a.handleExitCoder(cCtx, beforeErr)