Allow switch flags anywhere in the pipeline. (#1375)

This commit is contained in:
Andrés N. Robalino 2020-02-11 03:49:00 -05:00 committed by GitHub
parent 0b2be52bb5
commit 24094acee9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -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<Flag>)> {
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(

View File

@ -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(