Reorder help <keyword> priority (#7929)

# Description

`help <keyword>` will now search for `<keyword>` in aliases first, then
commands. This matches the way the parser resolves aliases before
commands.

# User-Facing Changes

Not significant
This commit is contained in:
Jakub Žádník 2023-02-06 00:51:09 +02:00 committed by GitHub
parent aef88aa03e
commit e8d930f659
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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"));
}