mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 02:13:47 +01:00
Allow switch flags anywhere in the pipeline. (#1375)
This commit is contained in:
parent
0b2be52bb5
commit
24094acee9
@ -30,18 +30,18 @@ pub fn parse_command_tail(
|
|||||||
for (name, kind) in &config.named {
|
for (name, kind) in &config.named {
|
||||||
trace!(target: "nu::parse::trace_remaining", "looking for {} : {:?}", name, kind);
|
trace!(target: "nu::parse::trace_remaining", "looking for {} : {:?}", name, kind);
|
||||||
|
|
||||||
tail.move_to(0);
|
|
||||||
|
|
||||||
match &kind.0 {
|
match &kind.0 {
|
||||||
NamedType::Switch => {
|
NamedType::Switch => {
|
||||||
let switch = extract_switch(name, tail);
|
let switch = extract_switch(name, tail);
|
||||||
|
|
||||||
match switch {
|
match switch {
|
||||||
None => named.insert_switch(name, None),
|
None => named.insert_switch(name, None),
|
||||||
Some((_, flag)) => {
|
Some((pos, flag)) => {
|
||||||
named.insert_switch(name, Some(*flag));
|
named.insert_switch(name, Some(*flag));
|
||||||
rest_signature.remove_named(name);
|
rest_signature.remove_named(name);
|
||||||
tail.color_shape(flag.color(flag.span));
|
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<'_>,
|
tokens: &mut hir::TokensIterator<'_>,
|
||||||
) -> Option<(usize, Spanned<Flag>)> {
|
) -> Option<(usize, Spanned<Flag>)> {
|
||||||
let source = tokens.source();
|
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(
|
fn extract_mandatory(
|
||||||
|
@ -81,7 +81,7 @@ fn removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
|
|||||||
|
|
||||||
nu!(
|
nu!(
|
||||||
cwd: dirs.test(),
|
cwd: dirs.test(),
|
||||||
"rm src/* --recursive"
|
"rm --recursive src/*"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(!files_exist_at(
|
assert!(!files_exist_at(
|
||||||
|
Loading…
Reference in New Issue
Block a user