From 008e9051f7212a241c361d758ec7473f6452455f Mon Sep 17 00:00:00 2001 From: Imbris Date: Sun, 13 Mar 2022 15:40:52 -0400 Subject: [PATCH] Don't consume command args that fail parsing, so that optional args are properly skipped. --- server/src/cmd.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 66889f0ef9..7dfb7e7f77 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -443,9 +443,14 @@ fn edit_setting_feedback( 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>())? ) }