Skip to content

Commit 9cb84ac

Browse files
committed
added new ExecOptions: WithIIfOpt(cond, true_opt, false_opt) & WithIfOpt(cond, true_opt)
Signed-off-by: Hedzr Yeh <[email protected]>
1 parent 6829220 commit 9cb84ac

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

exec_withopts.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,20 @@ func WithGlobalPostActions(fns ...Invoker) ExecOption {
783783
w.postActions = append(w.postActions, fns...)
784784
}
785785
}
786+
787+
func WithIfOpt(condition bool, yes func() ExecOption) ExecOption {
788+
return WithIIfOpt(condition, yes, nil)
789+
}
790+
791+
func WithIIfOpt(condition bool, yes, no func() ExecOption) ExecOption {
792+
if condition {
793+
if yes != nil {
794+
return yes()
795+
}
796+
} else {
797+
if no != nil {
798+
return no()
799+
}
800+
}
801+
return nil
802+
}

0 commit comments

Comments
 (0)