cradle
cradle copied to clipboard
Allow to easily box an Input value
Sometimes it's convenient to conditionally provide an input to a command or not. Currently that is difficult due to the Input
values being typed. So for example this doesn't work:
cmd_unit!("ls", if true { "some-file" } else { () });
Currently this can be solved with something like:
cmd_unit!("ls", if true { vec!["some-file"] } else { vec![] });
But you could imagine situations where it's not that easy to find a workaround like this. So maybe it'd be good to have a BoxedInput
type:
cmd_unit!("ls", if true { BoxedInput("some-file") } else { BoxedInput(()) });
Another way to do this would be to have something like OptionInput
, analogous to OptionFuture
.
Something like:
struct OptionInput<I: Input>(Option<I>);
// With a boolean condition:
cmd_unit!("ls", OptionInput(condition.then("some-file")));
// With an option:
cmd_unit!("ls", OptionInput(Some("some-file")));
If we'd have a BoxedInput
, then users could also do something like:
let mut args: Vec<BoxedInput> = vec!["foo".boxed(), "bar".boxed(), LogCommand.boxed()];
if condition {
args.push(Stdin("input").boxed());
}
args.run();
With OptionInput
that wouldn't be possible, since the inner type would still leak out into the wrapper type. OptionInput
would of course also be useful, but BoxedInput
seems more general.
I think they're probably both useful, I wouldn't mind having both.