nushell/crates/nu-command/tests/commands/which.rs

108 lines
2.7 KiB
Rust
Raw Normal View History

Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
use nu_test_support::nu;
#[test]
fn which_ls() {
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
let actual = nu!("which ls | get type.0");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
assert_eq!(actual.out, "built-in");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
}
Re-implement aliases (#8123) # Description This PR adds an alternative alias implementation. Old aliases still work but you need to use `old-alias` instead of `alias`. Instead of replacing spans in the original code and re-parsing, which proved to be extremely error-prone and a constant source of panics, the new implementation creates a new command that references the old command. Consider the new alias defined as `alias ll = ls -l`. The parser creates a new command called `ll` and remembers that it is actually a `ls` command called with the `-l` flag. Then, when the parser sees the `ll` command, it will translate it to `ls -l` and passes to it any parameters that were passed to the call to `ll`. It works quite similar to how known externals defined with `extern` are implemented. The new alias implementation should work the same way as the old aliases, including exporting from modules, referencing both known and unknown externals. It seems to preserve custom completions and pipeline metadata. It is quite robust in most cases but there are some rough edges (see later). Fixes https://github.com/nushell/nushell/issues/7648, https://github.com/nushell/nushell/issues/8026, https://github.com/nushell/nushell/issues/7512, https://github.com/nushell/nushell/issues/5780, https://github.com/nushell/nushell/issues/7754 No effect: https://github.com/nushell/nushell/issues/8122 (we might revisit the completions code after this PR) Should use custom command instead: https://github.com/nushell/nushell/issues/6048 # User-Facing Changes Since aliases are now basically commands, it has some new implications: 1. `alias spam = "spam"` (requires command call) * **workaround**: use `alias spam = echo "spam"` 2. `def foo [] { 'foo' }; alias foo = ls -l` (foo defined more than once) * **workaround**: use different name (commands also have this limitation) 4. `alias ls = (ls | sort-by type name -i)` * **workaround**: Use custom command. _The common issue with this is that it is currently not easy to pass flags through custom commands and command referencing itself will lead to stack overflow. Both of these issues are meant to be addressed._ 5. TODO: Help messages, `which` command, `$nu.scope.aliases`, etc. * Should we treat the aliases as commands or should they be separated from regular commands? 6. Needs better error message and syntax highlight for recursed alias (`alias f = f`) 7. Can't create alias with the same name as existing command (`alias ls = ls -a`) * Might be possible to add support for it (not 100% sure) 8. Standalone `alias` doesn't list aliases anymore 9. Can't alias parser keywords (e.g., stuff like `alias ou = overlay use` won't work) * TODO: Needs a better error message when attempting to do so # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-27 08:44:05 +01:00
#[ignore = "TODO: Can't have alias recursion"]
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
#[test]
fn which_alias_ls() {
let actual = nu!("alias ls = ls -a; which ls | get path.0 | str trim");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
assert_eq!(actual.out, "Nushell alias: ls -a");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
}
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
2023-07-08 10:48:42 +02:00
#[test]
fn which_custom_alias() {
let actual = nu!(r#"alias foo = print "foo!"; which foo | to nuon"#);
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
2023-07-08 10:48:42 +02:00
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
assert_eq!(actual.out, r#"[[command, path, type]; [foo, "", alias]]"#);
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
2023-07-08 10:48:42 +02:00
}
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
#[test]
fn which_def_ls() {
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
let actual = nu!("def ls [] {echo def}; which ls | get type.0");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
assert_eq!(actual.out, "custom");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
}
Re-implement aliases (#8123) # Description This PR adds an alternative alias implementation. Old aliases still work but you need to use `old-alias` instead of `alias`. Instead of replacing spans in the original code and re-parsing, which proved to be extremely error-prone and a constant source of panics, the new implementation creates a new command that references the old command. Consider the new alias defined as `alias ll = ls -l`. The parser creates a new command called `ll` and remembers that it is actually a `ls` command called with the `-l` flag. Then, when the parser sees the `ll` command, it will translate it to `ls -l` and passes to it any parameters that were passed to the call to `ll`. It works quite similar to how known externals defined with `extern` are implemented. The new alias implementation should work the same way as the old aliases, including exporting from modules, referencing both known and unknown externals. It seems to preserve custom completions and pipeline metadata. It is quite robust in most cases but there are some rough edges (see later). Fixes https://github.com/nushell/nushell/issues/7648, https://github.com/nushell/nushell/issues/8026, https://github.com/nushell/nushell/issues/7512, https://github.com/nushell/nushell/issues/5780, https://github.com/nushell/nushell/issues/7754 No effect: https://github.com/nushell/nushell/issues/8122 (we might revisit the completions code after this PR) Should use custom command instead: https://github.com/nushell/nushell/issues/6048 # User-Facing Changes Since aliases are now basically commands, it has some new implications: 1. `alias spam = "spam"` (requires command call) * **workaround**: use `alias spam = echo "spam"` 2. `def foo [] { 'foo' }; alias foo = ls -l` (foo defined more than once) * **workaround**: use different name (commands also have this limitation) 4. `alias ls = (ls | sort-by type name -i)` * **workaround**: Use custom command. _The common issue with this is that it is currently not easy to pass flags through custom commands and command referencing itself will lead to stack overflow. Both of these issues are meant to be addressed._ 5. TODO: Help messages, `which` command, `$nu.scope.aliases`, etc. * Should we treat the aliases as commands or should they be separated from regular commands? 6. Needs better error message and syntax highlight for recursed alias (`alias f = f`) 7. Can't create alias with the same name as existing command (`alias ls = ls -a`) * Might be possible to add support for it (not 100% sure) 8. Standalone `alias` doesn't list aliases anymore 9. Can't alias parser keywords (e.g., stuff like `alias ou = overlay use` won't work) * TODO: Needs a better error message when attempting to do so # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-27 08:44:05 +01:00
#[ignore = "TODO: Can't have alias with the same name as command"]
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
#[test]
fn correct_precedence_alias_def_custom() {
let actual =
nu!("def ls [] {echo def}; alias ls = echo alias; which ls | get path.0 | str trim");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
assert_eq!(actual.out, "Nushell alias: echo alias");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
}
Re-implement aliases (#8123) # Description This PR adds an alternative alias implementation. Old aliases still work but you need to use `old-alias` instead of `alias`. Instead of replacing spans in the original code and re-parsing, which proved to be extremely error-prone and a constant source of panics, the new implementation creates a new command that references the old command. Consider the new alias defined as `alias ll = ls -l`. The parser creates a new command called `ll` and remembers that it is actually a `ls` command called with the `-l` flag. Then, when the parser sees the `ll` command, it will translate it to `ls -l` and passes to it any parameters that were passed to the call to `ll`. It works quite similar to how known externals defined with `extern` are implemented. The new alias implementation should work the same way as the old aliases, including exporting from modules, referencing both known and unknown externals. It seems to preserve custom completions and pipeline metadata. It is quite robust in most cases but there are some rough edges (see later). Fixes https://github.com/nushell/nushell/issues/7648, https://github.com/nushell/nushell/issues/8026, https://github.com/nushell/nushell/issues/7512, https://github.com/nushell/nushell/issues/5780, https://github.com/nushell/nushell/issues/7754 No effect: https://github.com/nushell/nushell/issues/8122 (we might revisit the completions code after this PR) Should use custom command instead: https://github.com/nushell/nushell/issues/6048 # User-Facing Changes Since aliases are now basically commands, it has some new implications: 1. `alias spam = "spam"` (requires command call) * **workaround**: use `alias spam = echo "spam"` 2. `def foo [] { 'foo' }; alias foo = ls -l` (foo defined more than once) * **workaround**: use different name (commands also have this limitation) 4. `alias ls = (ls | sort-by type name -i)` * **workaround**: Use custom command. _The common issue with this is that it is currently not easy to pass flags through custom commands and command referencing itself will lead to stack overflow. Both of these issues are meant to be addressed._ 5. TODO: Help messages, `which` command, `$nu.scope.aliases`, etc. * Should we treat the aliases as commands or should they be separated from regular commands? 6. Needs better error message and syntax highlight for recursed alias (`alias f = f`) 7. Can't create alias with the same name as existing command (`alias ls = ls -a`) * Might be possible to add support for it (not 100% sure) 8. Standalone `alias` doesn't list aliases anymore 9. Can't alias parser keywords (e.g., stuff like `alias ou = overlay use` won't work) * TODO: Needs a better error message when attempting to do so # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
2023-02-27 08:44:05 +01:00
#[ignore = "TODO: Can't have alias with the same name as command"]
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
#[test]
fn multiple_reports_for_alias_def_custom() {
let actual = nu!("def ls [] {echo def}; alias ls = echo alias; which -a ls | length");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
let length: i32 = actual.out.parse().unwrap();
2022-03-24 04:42:41 +01:00
assert!(length >= 2);
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
}
// `get_aliases_with_name` and `get_custom_commands_with_name` don't return the correct count of
// values
// I suspect this is due to the ScopeFrame getting discarded at '}' and the command is then
// executed in the parent scope
// See: parse_definition, line 2187 for reference.
#[ignore]
#[test]
fn correctly_report_of_shadowed_alias() {
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
let actual = nu!("alias xaz = echo alias1
def helper [] {
alias xaz = echo alias2
which -a xaz
}
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
helper | get path | str contains alias2");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
assert_eq!(actual.out, "true");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
}
#[test]
fn one_report_of_multiple_defs() {
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
let actual = nu!("def xaz [] { echo def1 }
def helper [] {
def xaz [] { echo def2 }
which -a xaz
}
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
helper | length");
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 1);
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
}
#[test]
fn def_only_seen_once() {
let actual = nu!("def xaz [] {echo def1}; which -a xaz | length");
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 1);
Obey precedence rules in which; Fix #2875 (#2885) * Obay precedence rules in which; Fix #2875 Before which did not obay the precedence of alias before def commands. Furthermore, `which -a echo` would only report either an alias or a def command or an internal command with the provided name. Not all. With this commit applied its fixed :) Example: ```shell /home/leo/repos/nushell(fix/which_reports_wrong_usage)> def echo [] {^echo hi} /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell custom command │ No 1 │ echo │ Nushell built-in command │ Yes 2 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── /home/leo/repos/nushell(fix/which_reports_wrong_usage)> alias echo = ^echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> echo hi there /home/leo/repos/nushell(fix/which_reports_wrong_usage)> which -a echo ───┬──────┬──────────────────────────┬───────── # │ arg │ path │ builtin ───┼──────┼──────────────────────────┼───────── 0 │ echo │ Nushell alias │ No 1 │ echo │ Nushell custom command │ No 2 │ echo │ Nushell built-in command │ Yes 3 │ echo │ /usr/bin/echo │ No ───┴──────┴──────────────────────────┴───────── ``` * Fix clippy lint * Fix vec always Some even if empty
2021-01-08 18:44:31 +01:00
}
#[test]
fn do_not_show_hidden_aliases() {
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
let actual = nu!("alias foo = echo foo
hide foo
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
which foo | length");
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0);
}
#[test]
fn do_not_show_hidden_commands() {
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
let actual = nu!("def foo [] { echo foo }
hide foo
change the output of `which` to be more explicit (#9646) related to - https://github.com/nushell/nushell/issues/9637#issuecomment-1629387548 # Description this PR changes the output of `which` from `table<arg: string, path: string, built-in: bool> (stream)` to `table<command: string, path: string, type: string> (stream)`. - `command`: same as `arg` but more explicit name - `path`: same as before, `null` when built-in - `type`: instead of `buil-in: bool` says if it's a `built-in` a `custom` command, an `alias` or an `external` # User-Facing Changes the output of `which` has changed ## some examples ```nushell > which open ╭───┬─────────┬──────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼──────────┤ │ 0 │ open │ │ built-in │ ╰───┴─────────┴──────┴──────────╯ ``` ```nushell > alias foo = print "foo" > which foo ╭───┬─────────┬──────┬───────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼───────┤ │ 0 │ foo │ │ alias │ ╰───┴─────────┴──────┴───────╯ ``` ```nushell > def bar [] {} > which bar ╭───┬─────────┬──────┬────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────┼────────┤ │ 0 │ bar │ │ custom │ ╰───┴─────────┴──────┴────────╯ ``` ```nushell > which git ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ git │ /usr/bin/git │ external │ ╰───┴─────────┴──────────────┴──────────╯ ``` ```nushell > which open git foo bar ╭───┬─────────┬──────────────┬──────────╮ │ # │ command │ path │ type │ ├───┼─────────┼──────────────┼──────────┤ │ 0 │ open │ │ built-in │ │ 1 │ git │ /usr/bin/git │ external │ │ 2 │ foo │ │ alias │ │ 3 │ bar │ │ custom │ ╰───┴─────────┴──────────────┴──────────╯ ``` # Tests + Formatting - :green_circle: `toolkit fmt` - :green_circle: `toolkit clippy` - :black_circle: `toolkit test` - :black_circle: `toolkit test stdlib` # After Submitting mention that in the release note
2023-07-21 02:10:53 +02:00
which foo | length");
let length: i32 = actual.out.parse().unwrap();
assert_eq!(length, 0);
}