diff --git a/crates/nu-parser/src/hir.rs b/crates/nu-parser/src/hir.rs index 6afcc9dfea..bb70adc3bb 100644 --- a/crates/nu-parser/src/hir.rs +++ b/crates/nu-parser/src/hir.rs @@ -74,11 +74,7 @@ impl Call { pub fn switch_preset(&self, switch: &str) -> bool { self.named .as_ref() - .and_then(|n| n.get(switch)) - .map(|t| match t { - NamedValue::PresentSwitch(_) => true, - _ => false, - }) + .map(|n| n.switch_present(switch)) .unwrap_or(false) } } diff --git a/crates/nu-parser/src/hir/named.rs b/crates/nu-parser/src/hir/named.rs index 49ae3125c0..81b2c31fef 100644 --- a/crates/nu-parser/src/hir/named.rs +++ b/crates/nu-parser/src/hir/named.rs @@ -82,6 +82,16 @@ impl NamedArguments { pub fn insert_mandatory(&mut self, name: impl Into, expr: SpannedExpression) { self.named.insert(name.into(), NamedValue::Value(expr)); } + + pub fn switch_present(&self, switch: &str) -> bool { + self.named + .get(switch) + .map(|t| match t { + NamedValue::PresentSwitch(_) => true, + _ => false, + }) + .unwrap_or(false) + } } impl PrettyDebugWithSource for NamedArguments { diff --git a/crates/nu-parser/src/parse_command.rs b/crates/nu-parser/src/parse_command.rs index 198372abb1..da29b2af4d 100644 --- a/crates/nu-parser/src/parse_command.rs +++ b/crates/nu-parser/src/parse_command.rs @@ -114,7 +114,7 @@ pub fn parse_command_tail( positional = positionals; } Err(reason) => { - if found_error.is_none() && !tail.source().contains("help") { + if found_error.is_none() && !named.switch_present("help") { found_error = Some(reason); } }