Repository navigation
Let an alias end with a flag that takes a value - #19623
Merged
Merged
Conversation
`alias myfind = find -r` stored `-r` without a value, so `myfind "txt$"` passed `txt$` to find's other parameters and returned an empty list with no error. The first word after such an alias now becomes the flag's value, and a bare use reports the missing value at the alias name. `--help` and `-h` after the alias still show help. The filled flag's name gets an empty span where its value starts, so argument spans and error labels stay at the use site even when the alias is defined in config.nu. Flatten skips flags with empty name spans. Reported in nushell#19616 (comment)
Contributor
Author
|
@zozo123 any ideas what's going on with ci now? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
alias myfind = find -rwas accepted, butmyfind "txt$"searched for the literal texttxt$and returned an empty list with no error. The alias kept-rwithout a value, so the next word went tofind's other parameters.Now the first word after such an alias becomes the flag's value, the way bash, zsh and fish expand aliases. If no word follows, the parser reports the missing value at the alias name.
--helpand-hstill show help, and tab completion after the alias offers the flag's values.Names in the alias still resolve where it's defined, so
alias ls = ls -astill doesn't call itself.Examples, main against this branch.
These work now:
alias myfind = find -r; ["file.txt" "x"] | myfind "txt$"[file.txt]alias myfind = find -r; ["FILE.TXT" "x"] | myfind "txt$" -i[FILE.TXT]alias hex = into int --radix; "ff" | hex 16255alias j = to json -i; {a: 1} | j 4These don't change:
extern "/bin/echo" [--foo: string, ...rest: string]; alias e = /bin/echo --foo; e bar--foo bar--foo baralias rep = str replace -a; "aaa" | rep a bbbbbbbalias myfind = find -r; [] | myfind --helpfindfindalias myfind = find -r; [] | myfind -hfindfindThese are now an error, the same one you get typing the expansion alone:
alias j = to json -i; {a: 1} | jalias myfind = find -r; ["file.txt"] | myfindextern "/bin/echo" [--foo: string, ...rest: string]; alias e = /bin/echo --foo; e--foodef cmd [--opt: any] { $opt }; alias c = cmd --opt; ctrueUser-facing changes (Release notes)
alias myfind = find -r,myfind "txt$"runsfind -r "txt$". Before, the flag got no value and the alias could return wrong results with no error.extern.Breaking Changes
1. Using the alias with nothing after it is now a parse error
-i, so you get the default 2-space indent.MissingFlagParam, pointing atj.Because it fails at parse time, a
config.nuor module that uses such an alias this way anywhere now fails to load, not just that one line. The memory note for this branch already records this as the intended break.2. The first word after the alias now goes to the flag instead of to the positional arguments
{opt: true, rest: [x, y]}. A string flag got the booleantrue.{opt: x, rest: [y]}.If the flag is typed
int, the same call used to run withopt: true. Nowxfails the type check as a parse error.Additional notes
--helpand-hexception applies only to aliases.find -r --helpstill searches for--help.