|
I have an ancient python script I'm converting to Rust which enables me to pass options like so: where the arguments to |
Replies: 2 comments 1 reply
|
clap can group these per occurrence. give the arg ran it on Arg::new("s").short('s').action(ArgAction::Append).num_args(1..)
// then:
m.get_occurrences::<String>("s").unwrap()
.map(|o| o.cloned().collect::<Vec<_>>()).collect::<Vec<_>>()that gives |
|
awesome thank you! |
clap can group these per occurrence. give the arg
num_args(1..)so it collects values until the next-flag, plusArgAction::Appendso each-sstarts its own occurrence, then read it back withget_occurrencesinstead ofget_many.ran it on
-s a b -s c d --foo(clap 4.6.1):that gives
[["a", "b"], ["c", "d"]], and--foostill parses fine since it ends the last group.get_manyflattens the same data to["a", "b", "c", "d"], which is the usual trap here.get_occurrencesis the stabilized form of the oldgrouped_values_of