nushell / nushell

A new type of shell
https://www.nushell.sh/
MIT License
30.93k stars 1.58k forks source link

confusing output from `show` command #13151

Open backwardspy opened 3 weeks ago

backwardspy commented 3 weeks ago

Describe the bug

i've been learning nushell, and today i stumbled across something a little confusing.

i was running help shells to see if it supported any options. this is what it showed me:

$ help shells
Alias for `show`

Alias: shells

Expansion:
  show

i hadn't realised there was an alias, so i tried it:

$ show
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #6:1:1]
 1 │ show
   · ──┬─
   ·   ╰── Command `show` not found
   ╰────
  help: There is a built-in command with the same name

my understanding is that nushell will always prefer a built-in command over an external one unless i use ^, yet here it is telling me that it's failed as an external command, but available as a built-in one?

nushell implies that this command exists in some other contexts:

 $ showz
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #11:1:1]
 1 │ showz
   · ──┬──
   ·   ╰── Command `showz` not found
   ╰────
  help: Did you mean `show`?

but there is no available help for it:

$ help show
Error: nu::parser::not_found

  × Not found.
   ╭─[entry #12:1:6]
 1 │ help show
   ·      ──┬─
   ·        ╰── did not find anything under this name
   ╰────

i'm not sure if this is actually a bug or not, but at the least perhaps some of this output could be more helpful in explaining what i'm looking at.

How to reproduce

run show in nushell 0.94.2

Expected behavior

i expected nu to either tell me that such a command does not exist, or run the built-in command by that name.

Screenshots

No response

Configuration

key value
version 0.94.2
major 0
minor 94
patch 2
branch
commit_hash be8c1dc0066cd1034a6b110a622f47b516bfe029
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.77.2 (25ef9e3d8 2024-04-09)
rust_channel 1.77.2-x86_64-pc-windows-msvc
cargo_version cargo 1.77.2 (e52e36006 2024-03-26)
build_time 2024-06-03 19:27:48 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, system-clipboard, trash, which
installed_plugins

Additional context

edit: i've just noticed that next and prev give the same output, after looking at this: https://github.com/nushell/nushell/blob/b1cf0e258dc103f28b23190e495a2695bb0f9c97/crates/nu-std/std/dirs.nu#L24-L96

fdncred commented 3 weeks ago

These are the commands that are available without doing a use std in the repl. https://github.com/nushell/nushell/blob/b1cf0e258dc103f28b23190e495a2695bb0f9c97/crates/nu-std/src/lib.rs#L54-L67

You'll notice that show isn't in there but its alias shells is.

❯ shells --help
Display current working directories.

Usage:
  > show

Flags:
  -h, --help - Display the help message for this command

However, I do agree that this stuff should work better.

NotTheDr01ds commented 3 weeks ago

Yes, it's confused me in the past as well, and I only now think I'm starting to grok it. Put slightly differently, those aliases are defined in std. It's possible for an alias in a module to:

Those aliases are imported at startup, but the original commands they point to are not.

However, I do agree that this stuff should work better.

+1 ;-)

(Rough thinking without any validation or research) Perhaps the original commands should also be imported? Or just reverse the alias and command names?

backwardspy commented 3 weeks ago

interesting, thanks for the added context! that does make sense. so this isn't a bug, just some potentially confusing help messages.

fdncred commented 3 weeks ago

I also don't like how shells --help lists show in the usage above. If I had my way, it would look more like this.

❯ shells --help
Display current working directories.

Usage:
  > shells (an alias to `show`)

Flags:
  -h, --help - Display the help message for this command

Another thing that bothers me is that help shells is different than shells --help.

❯ help shells
Alias for `show`

Alias: shells

Expansion:
  show
❯ shells --help 
Display current working directories.

Usage:
  > show

Flags:
  -h, --help - Display the help message for this command
ErichDonGubler commented 6 days ago

As @fdncred noted, this issue applies to all commands in the shells category. Not only are they exposed in a "prelude", these aliases are presented like other built-ins in documentation, too.

Oddly, the officials docs pages for dexit and enter on the Wayback Machine). Example screenshots showing the resolved drop and add commands in the Usage section[^1]:

Screenshot 2024-06-30 at 7 42 16 PM Screenshot 2024-06-30 at 7 42 27 PM

[^1]: A keen observer might note that there's other incorrect help, i.e., the dexit has a Subcommands section that appears to be incorrectly re-used from the drop built-in. I've filed an issue for this at #13278.

fdncred commented 6 days ago

Oddly, the officials docs pages for dexit and enter on the Wayback Machine). Example screenshots showing the resolved drop and add commands in the Usage section1:

I'm guessing that this is because exit and enter used to be normal nushell Rust commands. Changing them to the stdlib, which is all nushell scripting, was one of our first attempts at moving commands from Rust to nushell scripting. Although, it could be because the code has changed so much and there's a bug too.