From e8d930f6590bdedefe521794a9a82979d32c1e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Mon, 6 Feb 2023 00:51:09 +0200 Subject: [PATCH] Reorder `help ` priority (#7929) # Description `help ` will now search for `` in aliases first, then commands. This matches the way the parser resolves aliases before commands. # User-Facing Changes Not significant --- crates/nu-command/src/core_commands/help.rs | 8 ++++---- crates/nu-command/tests/commands/help.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/src/core_commands/help.rs b/crates/nu-command/src/core_commands/help.rs index f1a487d163..983dbb4c99 100644 --- a/crates/nu-command/src/core_commands/help.rs +++ b/crates/nu-command/src/core_commands/help.rs @@ -86,15 +86,15 @@ You can also learn more at https://www.nushell.sh/book/"#; } else if find.is_some() { help_commands(engine_state, stack, call) } else { - let result = help_commands(engine_state, stack, call); + let result = help_aliases(engine_state, stack, call); - let result = if let Err(ShellError::CommandNotFound(_)) = result { - help_aliases(engine_state, stack, call) + let result = if let Err(ShellError::AliasNotFound(_)) = result { + help_commands(engine_state, stack, call) } else { result }; - let result = if let Err(ShellError::AliasNotFound(_)) = result { + let result = if let Err(ShellError::CommandNotFound(_)) = result { help_modules(engine_state, stack, call) } else { result diff --git a/crates/nu-command/tests/commands/help.rs b/crates/nu-command/tests/commands/help.rs index 865659a8b2..0ced68a839 100644 --- a/crates/nu-command/tests/commands/help.rs +++ b/crates/nu-command/tests/commands/help.rs @@ -342,3 +342,15 @@ fn help_modules_main_2() { assert_eq!(actual.out, "spam"); } + +#[test] +fn help_alias_before_command() { + let code = &[ + "alias SPAM = print 'spam'", + "def SPAM [] { 'spam' }", + "help SPAM", + ]; + let actual = nu!(cwd: ".", nu_repl_code(code)); + + assert!(actual.out.contains("Alias")); +}