From 363dc51ba0db3b9540ef5574133319b89a0d98f8 Mon Sep 17 00:00:00 2001 From: Coen Fox <9779696+Gymea@users.noreply.github.com> Date: Sun, 10 Jan 2021 04:19:46 +1100 Subject: [PATCH] Add aliased command to which output (#2894) * Add aliased command to which output * Fix alias arguments not being displayed --- crates/nu-cli/src/commands/which_.rs | 16 +++++++++++++++- crates/nu-cli/tests/commands/which.rs | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/nu-cli/src/commands/which_.rs b/crates/nu-cli/src/commands/which_.rs index c90d75ec21..124ce424e6 100644 --- a/crates/nu-cli/src/commands/which_.rs +++ b/crates/nu-cli/src/commands/which_.rs @@ -61,7 +61,21 @@ fn get_entries_in_aliases(scope: &Scope, name: &str, tag: Tag) -> Vec { .get_aliases_with_name(name) .unwrap_or_default() .into_iter() - .map(|_| create_entry!(name, "Nushell alias", tag.clone(), false)) + .map(|spans| { + spans + .into_iter() + .map(|span| span.item) + .collect::>() + .join(" ") + }) + .map(|alias| { + create_entry!( + name, + format!("Nushell alias: {}", alias), + tag.clone(), + false + ) + }) .collect::>(); trace!("Found {} aliases", aliases.len()); aliases diff --git a/crates/nu-cli/tests/commands/which.rs b/crates/nu-cli/tests/commands/which.rs index bb1a554dab..677154884a 100644 --- a/crates/nu-cli/tests/commands/which.rs +++ b/crates/nu-cli/tests/commands/which.rs @@ -17,7 +17,7 @@ fn which_alias_ls() { "alias ls = ls -a; which ls | get path | str trim" ); - assert_eq!(actual.out, "Nushell alias"); + assert_eq!(actual.out, "Nushell alias: ls -a"); } #[test] @@ -37,7 +37,7 @@ fn correct_precedence_alias_def_custom() { "def ls [] {echo def}; alias ls = echo alias; which ls | get path | str trim" ); - assert_eq!(actual.out, "Nushell alias"); + assert_eq!(actual.out, "Nushell alias: echo alias"); } #[test]