fixes which showing aliases as built-in nushell commands (#9580)

fixes #8577 

# Description
Currently, using `which` on an alias describes it as a nushell built-in
command:
```bash
> alias foo = print "foo!"                                                                                                                                                                                   > which ls foo --all                                                                                                                                                                                        
╭───┬─────┬──────────────────────────┬──────────╮
│ # │ arg │           path           │ built-in │
├───┼─────┼──────────────────────────┼──────────┤
│ 0 │ ls  │ Nushell built-in command │ true     │
│ 1 │ ls  │ /bin/ls                  │ false    │
│ 2 │ foo │ Nushell built-in command │ true     │
╰───┴─────┴──────────────────────────┴──────────╯
```

This PR fixes the behaviour above to the following:
```bash
> alias foo = print "foo!"
> which ls foo --all
╭───┬─────┬──────────────────────────┬──────────╮
│ # │ arg │           path           │ built-in │
├───┼─────┼──────────────────────────┼──────────┤
│ 0 │ ls  │ Nushell built-in command │ true     │
│ 1 │ ls  │ /bin/ls                  │ false    │
│ 2 │ foo │ Nushell alias            │ false    │
╰───┴─────┴──────────────────────────┴──────────╯
```

# User-Facing Changes
Passing in an alias to `which` will no longer return `Nushell built-in
command`, `true` for `path` and `built-in` respectively.

# Tests + Formatting

# After Submitting
This commit is contained in:
Ayush Singh
2023-07-08 09:48:42 +01:00
committed by GitHub
parent 8e38596bc9
commit ad125abf6a
2 changed files with 15 additions and 0 deletions

View File

@ -21,6 +21,19 @@ fn which_alias_ls() {
assert_eq!(actual.out, "Nushell alias: ls -a");
}
#[test]
fn which_custom_alias() {
let actual = nu!(
cwd: ".",
r#"alias foo = print "foo!"; which foo | to nuon"#
);
assert_eq!(
actual.out,
"[[arg, path, built-in]; [foo, \"Nushell alias\", false]]"
);
}
#[test]
fn which_def_ls() {
let actual = nu!(