mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 23:49:44 +01:00
suppress the parser error for an insufficient number of required arguments if the named keyword argument 'help' is given (#1659)
This commit is contained in:
parent
846a779516
commit
e7767ab7b3
@ -30,3 +30,32 @@ fn summarizes() {
|
|||||||
// 50%
|
// 50%
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn help() {
|
||||||
|
Playground::setup("histogram_test_help", |dirs, _sandbox| {
|
||||||
|
let help_command = nu!(
|
||||||
|
cwd: dirs.test(), pipeline(
|
||||||
|
r#"
|
||||||
|
help histogram
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
let help_short = nu!(
|
||||||
|
cwd: dirs.test(), pipeline(
|
||||||
|
r#"
|
||||||
|
histogram -h
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
let help_long = nu!(
|
||||||
|
cwd: dirs.test(), pipeline(
|
||||||
|
r#"
|
||||||
|
histogram --help
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(help_short, help_command);
|
||||||
|
assert_eq!(help_long, help_command);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -976,11 +976,14 @@ fn parse_internal_command(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if positional.len() < required_arg_count && error.is_none() {
|
if positional.len() < required_arg_count && error.is_none() {
|
||||||
let (_, name) = &signature.positional[positional.len()];
|
// to make "command -h" work even if required arguments are missing
|
||||||
error = Some(ParseError::argument_error(
|
if !named.named.contains_key("help") {
|
||||||
lite_cmd.name.clone(),
|
let (_, name) = &signature.positional[positional.len()];
|
||||||
ArgumentError::MissingMandatoryPositional(name.to_owned()),
|
error = Some(ParseError::argument_error(
|
||||||
));
|
lite_cmd.name.clone(),
|
||||||
|
ArgumentError::MissingMandatoryPositional(name.to_owned()),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !named.is_empty() {
|
if !named.is_empty() {
|
||||||
|
Loading…
Reference in New Issue
Block a user