-
I was wondering how I could achieve providing a calculated default for a #[test]
fn default_positional() {
use bpaf;
let roots = bpaf::positional::<String>("ROOTS")
.fallback_with::<_, String>(|| Ok(String::from(".")))
.many();
struct Roots { roots: Vec<String>, }
let r = construct!(Roots {roots}).to_options().run_inner(Args::from(&[]));
assert_eq!(vec![String::from(".")], r.unwrap().roots);
} |
Beta Was this translation helpful? Give feedback.
Answered by
xitep
Sep 26, 2022
Replies: 2 comments
-
one way to achieve a default value would be this: let roots = bpaf::positional::<String>("ROOTS").many().map(|items| {
if items.is_empty() {
vec![String::from(".")]
} else {
items
}
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
pacak
-
Since 0.8.0 you can use let a = short('a')
.argument::<u32>("ARG")
.some("potatoes")
.fallback(vec![1, 2, 3]); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
one way to achieve a default value would be this: