Skip to content

Wrong ... expand for some commands #5196

Closed

Description

@mxfp0

Describe the bug

On go we use ... do indicate all sub-folders: go test -coverprofile=coverage.out -cover ./pkg/...

Cases like this shouldn't be expanded.

How to reproduce

On any go project you can try to run the tests by doing:

$ go test -coverprofile=coverage.out -cover ./pkg/...
no Go files in /Users/herlon/go/src/github.com/herlon214

Because ... is expanded it tries to run the tests in the wrong folder.

Expected behavior

$ go test -coverprofile=coverage.out -cover ./pkg/...
ok      github.com/herlon214/sonarqube-pr-issues/pkg/scm        0.179s  coverage: 87.7% of statements
ok      github.com/herlon214/sonarqube-pr-issues/pkg/sonarqube  0.234s  coverage: 81.1% of statements

Screenshots

asciicast

Configuration

key value
version 0.61.0
branch main
tag v0.5.1
short_commit 87c684c
commit_hash 87c684c
commit_date 2022-04-13 18:42:57 +00:00
build_os macos-x86_64
rust_version rustc 1.60.0 (7737e0b5c 2022-04-04)
rust_channel stable-x86_64-apple-darwin
cargo_version cargo 1.60.0 (d1fd9fe2c 2022-03-01)
pkg_version 0.61.0
build_time 2022-04-13 21:33:32 +02:00
build_rust_channel release
features default, trash, which, zip
installed_plugins

Additional context

No response

Activity

  1. sophiajt commented on Apr 14, 2022

    @sophiajt
    Contributor

    I thought we changed it so ... only expanded at the front? hmmm

    Maybe we should use @strega-nil's idea and do that?

  2. kubouch commented on Apr 15, 2022

    @kubouch
    Contributor

    I'm thinking we should have a way to disable path expansions. There are use cases where you just want to pass the raw string. For example, recently, I wanted to remove a directory named ~ I accidentally created. It might be quite hard, though, since path expansions happen all over the place.

  3. leroycep commented on Apr 16, 2022

    @leroycep

    I am running into a similar issue with tar. It will change the path the file is packaged into depending on if the path is relative or absolute. Since . is expanded to the full absolute path by nushell, I can't make the packaged files top-level.

  4. added
    category:bug
    status:needs-design
    on Apr 16, 2022
  5. kubouch commented on Apr 16, 2022

    @kubouch
    Contributor

    Should we just disable path expansion on externals altogether? 🤔 I'm wondering if it would break anything but you can always path expand manually.

  6. strega-nil commented on Apr 16, 2022

    @strega-nil
    Contributor

    @kubouch @leroycep at least the . and .. thing has been implemented in #5180; however, this does not change the behavior of .... If we wanted to, we could only expand ...+ at the beginning of paths, but that would result in Weird Behavior imo.

  7. BatmanAoD commented on May 13, 2022

    @BatmanAoD
    Contributor

    Is there a way to explicitly suppress path expansion? './...' and "./..." behave the same way as ./... for me, so quotes don't seem to suppress expansion.

  8. kubouch commented on May 14, 2022

    @kubouch
    Contributor

    @BatmanAoD No, but there should be. You can try ./... but I think it will expand as well.

  9. BatmanAoD commented on May 16, 2022

    @BatmanAoD
    Contributor

    😆 😭

    go: warning: "`./...`" matched no packages
    
  10. eyepatchParrot commented on Jun 7, 2022

    @eyepatchParrot

    I have a simpler example here:

    > echo '...'
    ...
    > ^echo '...'
    ../..
    

    My expectation is that there would be a way of quoting a string so that it isn't path expanded.

  11. BatmanAoD commented on Jun 29, 2023

    @BatmanAoD
    Contributor

    It appears that Nu no longer expands ... in most cases. (I'm having a hard time understanding the exact rules; it seems that ls might be a special case, even though type ls states that it's using my standard GNU version, not a built-in.)

  12. amtoine commented on Jun 29, 2023

    @amtoine
    Member

    @BatmanAoD

    It appears that Nu no longer expands ... in most cases. (I'm having a hard time understanding the exact rules; it seems that ls might be a special case, even though type ls states that it's using my standard GNU version, not a built-in.)

    do you have an example where ... does not expand and it should? 😋

  13. BatmanAoD commented on Jun 30, 2023

    @BatmanAoD
    Contributor

    @amtoine I meant that I don't know what the rules should be, since my only context for the behavior is this thread and my own experimentation. Searching for "..." in the Book doesn't seem to yield any useful results, and it's not mentioned in help path expand, so I don't even know how to find documentation about what the expected expansion behavior is.

    What I've observed is that using the full path of my ls binary has different behavior than just using ls as the command name:

    ~/sandbox/git/sub> type ls                                                                                                                                                             06/29/2023 05:37:30 PM
    ls is /opt/homebrew/opt/coreutils/libexec/gnubin/ls
    ~/sandbox/git/sub> ls ...                                                                                                                                                              06/29/2023 05:37:36 PM
    ╭───┬──────────────┬──────┬───────┬──────────────╮
    │ # │     name     │ type │ size  │   modified   │
    ├───┼──────────────┼──────┼───────┼──────────────┤
    │ 0 │ ../../git    │ dir  │ 192 B │ a minute ago │
    │ 1 │ ../../go     │ dir  │  96 B │ 2 days ago   │
    │ 2 │ ../../pyquil │ dir  │ 128 B │ 6 hours ago  │
    │ 3 │ ../../rust   │ dir  │ 128 B │ 2 weeks ago  │
    ╰───┴──────────────┴──────┴───────┴──────────────╯
    ~/sandbox/git/sub> /opt/homebrew/opt/coreutils/libexec/gnubin/ls ...                                                                                                                   06/29/2023 05:37:44 PM
    ls: cannot access '...': No such file or directory
    

    Coming from other shells, this seems surprising (since normally I'd expect that type would report exactly what a command will do, and if it's an external binary, replacing the command with the full binary path shouldn't change anything except what the binary receives as arg[0]). But "surprising" doesn't necessarily seem "wrong", since, again, I don't know what the intended behavior is.

  14. BatmanAoD commented on Jun 30, 2023

    @BatmanAoD
    Contributor

    @amtoine To be clear, when I said that Nu "no longer expands ... in most cases", I meant that this GitHub issue might be resolved. In particular, it seems that there is no longer any problem using standard Go commands in Nu.

  15. amtoine commented on Jun 30, 2023

    @amtoine
    Member

    @BatmanAoD

    about the first part:

    there is a little confusion there 😉
    type is an external command, probably some system command that gives the path of the binary linked to some command name, e.g. ls is /opt/homebrew/opt/coreutils/libexec/gnubin/ls

    now ls is the builtin ls command in Nushell, which does not have anything to do with the one on your system 😮

    so when you run /opt/homebrew/opt/coreutils/libexec/gnubin/ls, it's like running ^ls, i.e. the external command.
    when you run ls, it's the builtin command 👍

    Note
    i bet you'll get something like the following 😏

    > which ls
    ╭───┬─────┬──────────────────────────┬──────────╮
    │ # │ arg │           path           │ built-in │
    ├───┼─────┼──────────────────────────┼──────────┤
    │ 0 │ ls  │ Nushell built-in command │ true     │
    ╰───┴─────┴──────────────────────────┴──────────╯
    > which ^ls
    ╭───┬─────┬───────────────────────────────────────────────┬──────────╮
    │ # │ arg │                     path                      │ built-in │
    ├───┼─────┼───────────────────────────────────────────────┼──────────┤
    │ 0 │ ls  │ /opt/homebrew/opt/coreutils/libexec/gnubin/ls │ false    │
    ╰───┴─────┴───────────────────────────────────────────────┴──────────╯

    To be clear, when I said that Nu "no longer expands ... in most cases", I meant that this GitHub issue might be resolved. In particular, it seems that there is no longer any problem using standard Go commands in Nu.

    this is good new 🥳
    have you been able to not reproduce the example of the OP then?
    if so, we can close this and see if the bug reappears 😌

  16. BatmanAoD commented on Jun 30, 2023

    @BatmanAoD
    Contributor

    @amtoine Yes, as far as I can tell, this issue should be closed. (Which is great, because it was one of the blockers for me adopting Nushell!)

    The rest of this comment is about type and why its behavior is confusing. I think it would be helpful (especially for Mac users) for Nu to alias type to which by default.

    I had forgotten that type isn't built in to nu... but apparently type itself "lies" about this:

    ~: type type                                                                                                                                      06/30/2023 12:33:15 PM
    type is a shell builtin
    ~: which type                                                                                                                                     06/30/2023 12:33:18 PM
    ╭───┬──────┬───────────────┬──────────╮
    │ # │ arg  │     path      │ built-in │
    ├───┼──────┼───────────────┼──────────┤
    │ 0 │ type │ /usr/bin/type │ false    │
    ╰───┴──────┴───────────────┴──────────╯
    

    Note that in most shells, type is more accurate than which, because which only searches for external binaries:

    !> type echo
    echo is a shell builtin
    !> which echo
    /opt/homebrew/opt/coreutils/libexec/gnubin/echo

    ...and, in most shells, type itself is a built-in whereas which is not:

    !> type type
    type is a shell builtin
    !> type which
    which is hashed (/usr/bin/which)

    Having type implemented as an external binary seems to be an oddity that's specific to BSD. On my Mac, type -a type prints:

    type is a shell builtin
    type is /usr/bin/type

    ...but this is not true of a Linux-based system running Bash:

    !> docker run -it bash
    bash-5.2# type -a type
    type is a shell builtin

    Looking at Mac's man page for builtins, it says:

    Commands marked ``No**'' under External do exist externally, but are implemented as scripts using a builtin command of the same name.

    ...and, indeed, type is marked No**... and cat /usr/bin/type prints:

    #!/bin/sh
    # $FreeBSD$
    # This file is in the public domain.
    builtin `echo ${0##*/} | tr \[:upper:] \[:lower:]` ${1+"$@"}
  17. amtoine commented on Jul 1, 2023

    @amtoine
    Member

    @amtoine Yes, as far as I can tell, this issue should be closed. (Which is great, because it was one of the blockers for me adopting Nushell!)

    this is good news, let's close this then if we can't reproduce the issue 👍

    The rest of this comment is about type and why its behavior is confusing. I think it would be helpful (especially for Mac users) for Nu to alias type to which by default.

    the quick fix here is to add

    alias type = which

    to your config.nu file 😋

  18. BatmanAoD commented on Jul 1, 2023

    @BatmanAoD
    Contributor

    @amtoine I emphasized "by default" very intentionally. Now that I know BSD (and only BSD!) has a type binary that invokes sh, it's not a problem for me. The problem is for people who don't know this, and, like me, expect type to give accurate information within the current shell.

  19. amtoine commented on Jul 2, 2023

    @amtoine
    Member

    @BatmanAoD

    i do not think it's Nushell's responsibility to make sure system-specific commands like type do what they "are supposed" to do in these other systems, it just sounds not tractable to me 😕

    however, maybe the Thinking in Nu chapter of the book could benefit from having a section talking about that!
    somethings that mentions the which command and explains that external / non built-in commands are not to be expected to integrate directly with Nushell because Nushell does not know about all of them 👍

    would that be a good middle ground for our scenario here @BatmanAoD? 😇

  20. BatmanAoD commented on Jul 2, 2023

    @BatmanAoD
    Contributor

    I'll leave it up to you, and I'm certainly sympathetic to the point that working around non-standard behavior isn't really "Nushell's responsibility." I do want to clarify, though, that BSD's behavior isn't "wrong" per se, it's just...weird and surprising, especially to people like me who are more accustomed to Linux. (I've only recently started using a Mac for work.) In most OSes, if your shell has a built-in, then you can't use the built-in from outside the shell; you'd almost expect that to be part of the definition of a "built-in." But instead, BSD-derived platforms will invoke sh and call the built-in from there, without any indication to the user that this is what's happening. (To be clear, the issue is not that I expected a command from outside of Nu to be integrated in some deeper way with Nu; the issue is that I thought type was a Nu built-in, because of the way type itself behaves.)

    Since Mac OS is a pretty common operating system, my point here is really just that this confusion will potentially recur. On Linux and Windows there's not really a problem, because attempting to use type just returns the standard missing-command error message.

    I realize that all of the built-ins "implemented as scripts" according to that BSD man page I linked are potentially confusing. But I think type is something of a special case just because it's such a useful tool when exploring a shell, and also because nu already has a built-in (which) that behaves the way type behaves in unix-y shells. Additionally, I think it's the one with the most potential for confusion, since it explicitly states that certain commands are built-ins...but they're built-in to sh, not nu. (The other really surprising command listed on that man page is unalias, for which I honestly can't think of a legitimate use case for the /usr/bin/unalias script; but as far as I can tell there are no "default" aliases in Mac OS, so in general, unalias <foo> will just print an error message.)

    So, basically, I just think that aliasing type -> which could prevent a lot of confusion and generally make nu behave in an unsurprising way for people coming from other shells; and I also can't think of any similar cases where a system binary on a common operating system would cause this specific type of confusion, where the output of the command doesn't make it immediately obvious that the command isn't a built-in. (To be fair, though, the fact that the output wasn't formatted as a table should have been a giveaway.)

    In any case, this is the last I'll say about it, and as I mentioned above, I do understand not making any change to address it, since it's essentially just a weird quirk of a certain operating system. I appreciate the suggestion of adding some text to "Thinking in Nu", but I'm not sure what would help, given that the problem is more about how type itself behaves. Maybe it could be added to a list of "footguns"?

    [Side note: A potentially more robust, but also more complex, solution would be to have nu's command invocation logic prohibit directly invoking any of these posix shell built-ins as external scripts, without ^ or an explicit path. A list of these "prohibited" commands could be derived from scraping man builtin (perhaps while generating the default config file) or whenever a file under /usr/bin/ is invoked by examining the file contents (which are always the same four lines: the shebang, a FreeBSD public domain notice, and then a fancy builtin $0). ]

  21. amtoine commented on Jul 4, 2023

    @amtoine
    Member

    @BatmanAoD
    thanks for the writeup, this is very clear and very sensible 👍

    i'll talk about that in the next @nushell/core-team meeting, just to see what others think about that 😉

  22. BatmanAoD commented on Jul 4, 2023

    @BatmanAoD
    Contributor

    @amtoine Thanks very much!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:bugstatus:needs-design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions