-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move most of the peculiar argument handling for external calls into the parser #13089
Conversation
… to know about the expr
Awesome! I was going to suggest that we probably shouldn't be doing the external arg parsing in |
Great! There are a few things I'd appreciate a review on. One in particular is how I handled string interpolations that should turn into globs - I just made them This is my first time really digging into the nushell parser code and... well, it's not bad, it's easy enough to understand for me, but I can understand why we're trying to push forward the new parser. There are a lot of special cases and it's not as much based on building up smaller parsers as I would have hoped, and there aren't really a lot of parser combinator type helper functions either. But I'm also probably not as familiar with general patterns there as I could be, so some more review of those changes would be appreciated too. |
This bare word string interpolation seems pretty epic to me 🚀. Reduces some typing. What about single quotes and backtick quotes? I haven't tried this PR yet.
|
@fdncred IMO,
should expand tilde because it's a bareword. The first one shouldn't, I agree. |
Nope
We don't have that syntax yet I think but if we did it probably should. |
Then I don't understand when is the
|
@devyn It would be good to change the default_config.nu since you added I realize this is mostly a run-external PR but I'm wondering if some internal commands need to be updated to support bare word string interpolation? Or maybe ❯ let bin_name = "bin"
❯ ls ~/.cargo/($bin_name)
Error: nu::shell::directory_not_found
× Directory not found
╭─[entry #2:1:4]
1 │ ls ~/.cargo/($bin_name)
· ──────────┬─────────
· ╰── directory not found
╰────
help: /Users/fdncred/.cargo/($bin_name) does not exist but these work ❯ echo ~/.cargo/($bin_name)
~/.cargo/bin
❯ ^echo ~/.cargo/($bin_name)
/Users/fdncred/.cargo/bin
❯ ^ls ~/.cargo/($bin_name)
... all my bins ... |
Sure, I'll do that.
I didn't really do anything to make this work with internal commands yet. The complicated bit is that there are a bunch of different syntax shapes that are used. I think I can add it for Overall I'm not very satisfied with how this is currently designed and it feels like it should be more compositional, so we don't need many variants of the same expressions just to support interpolation |
# Description Just missed this during #13089. Adds `shape_glob_interpolation` to the config. This actually isn't really going to be seen at all yet, so I debated whether it's really needed at all. It's only used to highlight the quotes themselves, and we don't have any quoted glob interpolations at the moment.
…rings (#13218) # Description @hustcer reported that slashes were disappearing from external args since #13089: ``` $> ossutil ls oss:https://abc/b/c Error: invalid cloud url: "oss:/abc/b/c", please make sure the url starts with: "oss:https://" $> ossutil ls 'oss:https://abc/b/c' Error: oss: service returned error: StatusCode=403, ErrorCode=UserDisable, ErrorMessage="UserDisable", RequestId=66791EDEFE87B73537120838, Ec=0003-00000801, Bucket=abc, Object= ``` I narrowed this down to the ndots handling, since that does path parsing and path reconstruction in every case. I decided to change that so that it only activates if the string contains at least `...`, since that would be the minimum trigger for ndots, and also to not activate it if the string contains `:https://`, since it's probably undesirable for a URL. Kind of a hack, but I'm not really sure how else we decide whether someone wants ndots or not. # User-Facing Changes - bare strings not containing ndots are not modified - bare strings containing `:https://` are not modified # Tests + Formatting Added tests to prevent regression.
Description
We've had a lot of different issues and PRs related to arg handling with externals since the rewrite of
run-external
in #12921:.
expanded incorrectly as external argument #12950run_external::expand_glob()
to return paths that are PWD-relative but reflect the original intent #13028=
sign #13073Many of these are caused by the argument handling of external calls and
run-external
being very special and involving the parser handing quoted strings over torun-external
so that it knows whether to expand tildes and globs and so on. This is really unusual and also makes it harder to userun-external
, and also harder to understand it (and probably is part of the reason why it was rewritten in the first place).This PR moves a lot more of that work over to the parser, so that by the time
run-external
gets it, it's dealing with much more normal Nushell values. In particular:run-external
doesn't have to do itGlob
containingExpr::StringInterpolation
now produceValue::Glob
instead, with the quoted status from the expr passed through so we know if it was a bare wordglob
now possible, but not implementedValue::Glob(_, false)
instead of looking at the expr, externals now support glob typesUser-Facing Changes
Bare word interpolation works for external command options, and otherwise embedded in other strings:
Bare word interpolation expands for external command head/args:
Ndots are now supported for the head of an external command (
^.../foo
works)Glob values are now supported for head/args of an external command, and expanded appropriately:
run-external
now works more like any other command, without expecting a special call conventionfor its args:
Tests + Formatting
Lots of tests added and cleaned up. Some tests that weren't active on Windows changed to use
nu --testbin cococo
so that they can work. Added a test for Linux only to make sure tilde expansion of commands works, because changingHOME
there causes~
to reliably change.toolkit fmt
toolkit clippy
toolkit test
toolkit test stdlib
After Submitting