diff --git a/crates/nu-parser/src/parse_command.rs b/crates/nu-parser/src/parse_command.rs index b52461df8e..47edbf2664 100644 --- a/crates/nu-parser/src/parse_command.rs +++ b/crates/nu-parser/src/parse_command.rs @@ -30,18 +30,18 @@ pub fn parse_command_tail( for (name, kind) in &config.named { trace!(target: "nu::parse::trace_remaining", "looking for {} : {:?}", name, kind); - tail.move_to(0); - match &kind.0 { NamedType::Switch => { let switch = extract_switch(name, tail); match switch { None => named.insert_switch(name, None), - Some((_, flag)) => { + Some((pos, flag)) => { named.insert_switch(name, Some(*flag)); rest_signature.remove_named(name); tail.color_shape(flag.color(flag.span)); + tail.move_to(pos); + tail.expand_infallible(MaybeSpaceShape); } } } @@ -273,7 +273,15 @@ fn extract_switch( tokens: &mut hir::TokensIterator<'_>, ) -> Option<(usize, Spanned)> { let source = tokens.source(); - tokens.extract(|t| t.as_flag(name, &source).map(|flag| flag.spanned(t.span()))) + let switch = tokens.extract(|t| t.as_flag(name, &source).map(|flag| flag.spanned(t.span()))); + + match switch { + None => None, + Some((pos, flag)) => { + tokens.remove(pos); + Some((pos, flag)) + } + } } fn extract_mandatory( diff --git a/tests/commands/rm.rs b/tests/commands/rm.rs index 7fa07e571b..8cdb1e6283 100644 --- a/tests/commands/rm.rs +++ b/tests/commands/rm.rs @@ -81,7 +81,7 @@ fn removes_deeply_nested_directories_with_wildcard_and_recursive_flag() { nu!( cwd: dirs.test(), - "rm src/* --recursive" + "rm --recursive src/*" ); assert!(!files_exist_at(