Skip to content

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

Merged
sholderbach merged 7 commits into
nushell:mainfrom
a13h:fix/8577-which-alias-built-in-commands
Jul 8, 2023
Merged

sholderbach merged 7 commits into
nushell:mainfrom
a13h:fix/8577-which-alias-built-in-commands

Conversation

@a13h

@a13h a13h commented Jul 1, 2023 •

Copy link
Copy Markdown
Contributor

fixes #8577

Description

Currently, using which on an alias describes it as a nushell built-in command:

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

> 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

Comment thread crates/nu-command/src/system/which_.rs Resolved

@amtoine amtoine left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a simple change which solves the issue, thanks 👌

just a minor change as you probably guessed 😉

Comment thread crates/nu-command/src/system/which_.rs Resolved
@amtoine amtoine linked an issue Jul 2, 2023 that may be closed by this pull request
@amtoine amtoine changed the title (Issue #8577) fixes which showing aliases as built-in nushell commands fixes which showing aliases as built-in nushell commands Jul 2, 2023
@amtoine

amtoine commented Jul 2, 2023

Copy link
Copy Markdown
Member

@AyushSingh13
what do you think about adding a little test to make sure this behaviour is correct in the future?
a simple little scripts as in the PR description 😋

@sholderbach

Copy link
Copy Markdown
Member

@amtoine @AyushSingh13

We already have some which tests involving aliases, that may be worth revisiting and expanding in https://github.com/nushell/nushell/blob/main/crates/nu-command/tests/commands/which.rs

Maybe the following works now and doesn't need to be ignored after @kubouch 's new alias work:

#[ignore = "TODO: Can't have alias recursion"]
#[test]
fn which_alias_ls() {
let actual = nu!(
cwd: ".",
"alias ls = ls -a; which ls | get path.0 | str trim"
);
assert_eq!(actual.out, "Nushell alias: ls -a");
}

@kubouch

kubouch commented Jul 3, 2023

Copy link
Copy Markdown
Contributor

Yeah, some of these tests we might be able to un-ignore. Otherwise the PR looks good to me!

@amtoine

amtoine commented Jul 3, 2023

Copy link
Copy Markdown
Member

yup, if we have ignored test that we can un-ignore then let's go for it 😋

@a13h

a13h commented Jul 6, 2023

Copy link
Copy Markdown
Contributor Author

@AyushSingh13 what do you think about adding a little test to make sure this behaviour is correct in the future? a simple little scripts as in the PR description 😋

Of course! I've added a test which_custom_alias. However, the which_alias_ls() @sholderbach mentioned still fails because the path doesn't include the alias definition just yet. I was trying to figure out how to do this and bounced around Signature and Expressions a bit but haven't figured it out yet! If it's not urgent, would it be okay for me to open a new issue and PR for this? If not, I'm happy to look into it more to include the definitions in this PR itself :)

@amtoine

amtoine commented Jul 7, 2023

Copy link
Copy Markdown
Member

@AyushSingh13
do the tests pass with this PR?

it's hard to tell because the CI stops on Clippy 😮

if it passes i'd say let's leave this other issue for another PR, otherwise, it might be related so we should fix the tests in this PR 😋

@sholderbach

Copy link
Copy Markdown
Member

Of course! I've added a test which_custom_alias. However, the which_alias_ls() @sholderbach mentioned still fails because the path doesn't include the alias definition just yet. I was trying to figure out how to do this and bounced around Signature and Expressions a bit but haven't figured it out yet! If it's not urgent, would it be okay for me to open a new issue and PR for this? If not, I'm happy to look into it more to include the definitions in this PR itself :)

Mhh if the test that is currently ignored still fails for unrelated reasons, let's keep it out of this PR for now. (Maybe there is still a problem with "recursive" aliases)
Let's get your which output for the working aliases correct first.

@a13h

a13h commented Jul 7, 2023 •

Copy link
Copy Markdown
Contributor Author

@AyushSingh13 do the tests pass with this PR?

it's hard to tell because the CI stops on Clippy 😮

if it passes i'd say let's leave this other issue for another PR, otherwise, it might be related so we should fix the tests in this PR 😋

@amtoine - Apologies for that, I should've run those clippy, fmt and tests locally! The tests and clippy both passed before but fmt gave us this:

$ cargo fmt --all -- --check
Diff in /Users/ayush/projects/nushell/crates/nu-command/tests/commands/which.rs at line 24:                                                                                                                                                           
 #[test]                                                                                                                                                                                                                                              
 fn which_custom_alias() {                                                                                                                                                                                                                            
     let actual = nu!(                                                                                                                                                                                                                                
-        cwd: ".",                                                                                                                                                                                                                                    
+        cwd: ".",                                                                                                                                                                                                                                    
         r#"alias foo = print "foo!"; which foo | get path.0 | str trim"#                                                                                                                                                                             
     );   

I'm unsure what that diff is and not sure how I can go about comparing what it is - both lines look the same to me!

Either way, I've fixed this now, edited the test to use to nuon and made sure all tests are passing too 😊

@a13h
a13h marked this pull request as ready for review July 7, 2023 23:30

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks this looks good!

@sholderbach
sholderbach merged commit ad125ab into nushell:main Jul 8, 2023
@amtoine

amtoine commented Jul 8, 2023

Copy link
Copy Markdown
Member

@AyushSingh13

I'm unsure what that diff is and not sure how I can go about comparing what it is - both lines look the same to me!

there was a trailing whitespace before the patch 😋
i'm not sure cargo fmt shows trailing whitespaces properly 🤔

the easiest is to run cargo fmt --all, without the --check, so that cargo will patch the code for ya 👌
you can also use the toolkit.nu of the repo with toolkit fmt 😉

@a13h

a13h commented Jul 8, 2023

Copy link
Copy Markdown
Contributor Author

@AyushSingh13

I'm unsure what that diff is and not sure how I can go about comparing what it is - both lines look the same to me!

there was a trailing whitespace before the patch 😋 i'm not sure cargo fmt shows trailing whitespaces properly 🤔

the easiest is to run cargo fmt --all, without the --check, so that cargo will patch the code for ya 👌 you can also use the toolkit.nu of the repo with toolkit fmt 😉

Ah, that makes sense - thank you! Will go create the issue for including the alias definition and hopefully get deeper into things! thank you for all your help

@a13h
a13h deleted the fix/8577-which-alias-built-in-commands branch July 8, 2023 09:19
@amtoine

amtoine commented Jul 8, 2023

Copy link
Copy Markdown
Member

Ah, that makes sense - thank you!

anytime 😉
i've created the toolkit to not have to remember the cargo commands, i typically never run cargo with Nushell 😏

Will go create the issue for including the alias definition and hopefully get deeper into things!

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

which shows aliases as built-in commands

4 participants