Skip to content

Commit

Permalink
fix the exec order: internal action first, and command.OnAction follo…
Browse files Browse the repository at this point in the history
…wing
  • Loading branch information
hedzr committed Oct 22, 2024
1 parent 48c8bae commit c45c950
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions cli/worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func (w *workerS) exec(ctx context.Context, pc *parseCtx) (err error) {
}
}()

handled, err1 := w.handleActions(ctx, pc)
if handled || !w.errIsSignalOrNil(err1) {
err = err1
return
}

if !forceDefaultAction && lastCmd.CanInvoke() {
logz.VerboseContext(ctx, "invoke action of cmd, with args", "cmd", lastCmd, "args", pc.positionalArgs)
err = lastCmd.Invoke(ctx, pc.positionalArgs)
Expand All @@ -42,30 +48,12 @@ func (w *workerS) exec(ctx context.Context, pc *parseCtx) (err error) {
pc.forceDefaultAction, err = true, nil
}

handled, err1 := w.handleActions(ctx, pc)
// for k, action := range w.actions {
// if k&w.actionsMatched != 0 {
// logz.VerboseContext(ctx, "Invoking worker.actionsMatched", "hit-action", k, "actions", w.Actions())
// err, handled = action(pc, lastCmd), true
// break
// }
// }
if handled || !w.errIsSignalOrNil(err1) {
err = err1
return
}

// if pc.helpScreen {
// err = w.onPrintHelpScreen(pc, lastCmd)
// return
// }

if pc.forceDefaultAction {
err = w.onDefaultAction(ctx, pc, lastCmd)
return
}

logz.VerboseContext(ctx, "[cmdr] no onAction associate to cmd", "cmd", lastCmd)
logz.VerboseContext(ctx, "[cmdr] no onAction associated to cmd", "cmd", lastCmd)
err = w.onPrintHelpScreen(ctx, pc, lastCmd)
return
}
Expand Down

0 comments on commit c45c950

Please sign in to comment.