mirror of
https://github.com/nushell/nushell
synced 2024-12-25 04:23:10 +00:00
For some commands like `which` -h flag would trigger an error asking for missing required parameters instead of printing the help message as it does with --help. This commit adds a check in the command parser to avoid that.
This commit is contained in:
parent
a2443fbe02
commit
d1fcce0cd3
3 changed files with 12 additions and 6 deletions
|
@ -74,11 +74,7 @@ impl Call {
|
||||||
pub fn switch_preset(&self, switch: &str) -> bool {
|
pub fn switch_preset(&self, switch: &str) -> bool {
|
||||||
self.named
|
self.named
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|n| n.get(switch))
|
.map(|n| n.switch_present(switch))
|
||||||
.map(|t| match t {
|
|
||||||
NamedValue::PresentSwitch(_) => true,
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,16 @@ impl NamedArguments {
|
||||||
pub fn insert_mandatory(&mut self, name: impl Into<String>, expr: SpannedExpression) {
|
pub fn insert_mandatory(&mut self, name: impl Into<String>, expr: SpannedExpression) {
|
||||||
self.named.insert(name.into(), NamedValue::Value(expr));
|
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 {
|
impl PrettyDebugWithSource for NamedArguments {
|
||||||
|
|
|
@ -114,7 +114,7 @@ pub fn parse_command_tail(
|
||||||
positional = positionals;
|
positional = positionals;
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
if found_error.is_none() && !tail.source().contains("help") {
|
if found_error.is_none() && !named.switch_present("help") {
|
||||||
found_error = Some(reason);
|
found_error = Some(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue