Skip to content

Commit

Permalink
added new ExecOptions: WithIIfOpt(cond, true_opt, false_opt) & `W…
Browse files Browse the repository at this point in the history
…ithIfOpt(cond, true_opt)`

Signed-off-by: Hedzr Yeh <[email protected]>
  • Loading branch information
hedzr committed Feb 21, 2023
1 parent 6829220 commit 9cb84ac
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions exec_withopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,20 @@ func WithGlobalPostActions(fns ...Invoker) ExecOption {
w.postActions = append(w.postActions, fns...)
}
}

func WithIfOpt(condition bool, yes func() ExecOption) ExecOption {
return WithIIfOpt(condition, yes, nil)
}

func WithIIfOpt(condition bool, yes, no func() ExecOption) ExecOption {
if condition {
if yes != nil {
return yes()
}
} else {
if no != nil {
return no()
}
}
return nil
}

0 comments on commit 9cb84ac

Please sign in to comment.