Fix overlay's help message lead to internal error (#9087)

This commit is contained in:
WindSoilder 2023-05-03 19:08:54 +08:00 committed by GitHub
parent a7c1b363eb
commit 345cdef113
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -102,6 +102,16 @@ pub fn parse_keyword(
{ {
// Apply parse keyword side effects // Apply parse keyword side effects
let cmd = working_set.get_decl(call.decl_id); let cmd = working_set.get_decl(call.decl_id);
// check help flag first.
if call.named_iter().any(|(flag, _, _)| flag.item == "help") {
let call_span = call.span();
return Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call),
span: call_span,
ty: Type::Any,
custom_completion: None,
}]);
}
match cmd.name() { match cmd.name() {
"overlay hide" => parse_overlay_hide(working_set, call), "overlay hide" => parse_overlay_hide(working_set, call),

View File

@ -1312,3 +1312,13 @@ fn alias_overlay_new() {
assert_eq!(actual.out, "eggs"); assert_eq!(actual.out, "eggs");
assert_eq!(actual_repl.out, "eggs"); assert_eq!(actual_repl.out, "eggs");
} }
#[test]
fn overlay_help_no_error() {
let actual = nu!(cwd: ".", "overlay hide -h");
assert!(actual.err.is_empty());
let actual = nu!(cwd: ".", "overlay new -h");
assert!(actual.err.is_empty());
let actual = nu!(cwd: ".", "overlay use -h");
assert!(actual.err.is_empty());
}