Don't consume command args that fail parsing, so that optional args are properly skipped.

This commit is contained in:
Imbris 2022-03-13 15:40:52 -04:00
parent 6d101419c7
commit 008e9051f7

View File

@ -443,9 +443,14 @@ fn edit_setting_feedback<S: EditableSetting>(
macro_rules! parse_args {
($args:expr, $($t:ty),* $(, ..$tail:ty)? $(,)?) => {
{
let mut args = $args.into_iter();
let mut args = $args.into_iter().peekable();
(
$(args.next().and_then(|s| s.parse::<$t>().ok())),*
$({
let parsed = args.peek().and_then(|s| s.parse::<$t>().ok());
// Consume successfully parsed arg.
if parsed.is_some() { args.next(); }
parsed
}),*
$(, args.map(|s| s.to_string()).collect::<$tail>())?
)
}