Skip to content

Commit e914bc0

Browse files
committed
feat: add maybe args
Add CommandBuilder::maybe_with_arg and CommandBuilder::maybe_with_args
1 parent dc63493 commit e914bc0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/cmd.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@ pub trait CommandBuilder {
184184
self
185185
}
186186

187+
/// Add the argument if `apply` is `true`.
188+
fn maybe_with_arg<S>(self, apply: bool, arg: S) -> Self
189+
where
190+
Self: Sized,
191+
S: AsRef<OsStr>,
192+
{
193+
if apply {
194+
self.with_arg(arg)
195+
} else {
196+
self
197+
}
198+
}
199+
200+
/// Add the arguments if `apply` is `true`.
201+
fn maybe_with_args<I, S>(self, apply: bool, args: I) -> Self
202+
where
203+
Self: Sized,
204+
I: IntoIterator<Item = S>,
205+
S: AsRef<OsStr>,
206+
{
207+
if apply {
208+
self.with_args(args)
209+
} else {
210+
self
211+
}
212+
}
213+
187214
/// Akin to [`Command::env`].
188215
fn with_env<K, V>(self, key: K, val: V) -> Self
189216
where

0 commit comments

Comments
 (0)