From fb8f7b114e13ffc1a60741aba7d9b3d5ce09cb46 Mon Sep 17 00:00:00 2001 From: gipsyh Date: Wed, 27 Apr 2022 00:51:49 +0800 Subject: [PATCH] Fix use of `export/alias --help` bug (#5332) * fix alias --help bug Signed-off-by: SuYuheng * fix export --help bug Signed-off-by: SuYuheng Co-authored-by: SuYuheng --- crates/nu-parser/src/parse_keywords.rs | 12 +++++++ crates/nu-parser/src/parser.rs | 45 ++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 6f148b67c..b460918f6 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -529,6 +529,18 @@ pub fn parse_alias( expand_aliases_denylist, ); + if call.has_flag("help") { + return ( + Pipeline::from_vec(vec![Expression { + expr: Expr::Call(call), + span: span(spans), + ty: Type::Any, + custom_completion: None, + }]), + None, + ); + } + if spans.len() >= 4 { let alias_name = working_set.get_span_contents(spans[1]); diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 853a0dacf..3c322079d 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -4539,13 +4539,44 @@ pub fn parse_builtin_commands( b"module" => parse_module(working_set, &lite_command.parts, expand_aliases_denylist), b"use" => parse_use(working_set, &lite_command.parts, expand_aliases_denylist), b"source" => parse_source(working_set, &lite_command.parts, expand_aliases_denylist), - b"export" => ( - garbage_pipeline(&lite_command.parts), - Some(ParseError::UnexpectedKeyword( - "export".into(), - lite_command.parts[0], - )), - ), + b"export" => { + if let Some(decl_id) = working_set.find_decl(b"alias") { + let (call, _) = parse_internal_call( + working_set, + lite_command.parts[0], + &lite_command.parts[1..], + decl_id, + expand_aliases_denylist, + ); + if call.has_flag("help") { + ( + Pipeline::from_vec(vec![Expression { + expr: Expr::Call(call), + span: span(&lite_command.parts), + ty: Type::Any, + custom_completion: None, + }]), + None, + ) + } else { + ( + garbage_pipeline(&lite_command.parts), + Some(ParseError::UnexpectedKeyword( + "export".into(), + lite_command.parts[0], + )), + ) + } + } else { + ( + garbage_pipeline(&lite_command.parts), + Some(ParseError::UnexpectedKeyword( + "export".into(), + lite_command.parts[0], + )), + ) + } + } b"hide" => parse_hide(working_set, &lite_command.parts, expand_aliases_denylist), #[cfg(feature = "plugin")] b"register" => parse_register(working_set, &lite_command.parts, expand_aliases_denylist),