Skip to content

Commit

Permalink
Fix use of export/alias --help bug (nushell#5332)
Browse files Browse the repository at this point in the history
* fix alias --help bug

Signed-off-by: SuYuheng <yuheng.su@motiong.com>

* fix export --help bug

Signed-off-by: SuYuheng <yuheng.su@motiong.com>

Co-authored-by: SuYuheng <yuheng.su@motiong.com>
  • Loading branch information
2 people authored and fennewald committed Jun 27, 2022
1 parent 3c0280d commit 69d6000
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
12 changes: 12 additions & 0 deletions crates/nu-parser/src/parse_keywords.rs
Expand Up @@ -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]);

Expand Down
45 changes: 38 additions & 7 deletions crates/nu-parser/src/parser.rs
Expand Up @@ -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),
Expand Down

0 comments on commit 69d6000

Please sign in to comment.