You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have done a basic search through the issue tracker to find similar or related issues.
I have made myself familiar with the available features of Nushell for the particular area this enhancement request touches.
Related problem
When doing something like script.nu true false 011 nushell will make 011 into 11 and if we change the rest annotation from non annotated or annotated with any to string or glob it will error out because true and false are not globs.
The problem is that for example often programs that allows doing something like script.nu %command% and values in %command% don't usually quote true, false... or even pass things like 0011.
Recently #18372 changed rest when non annotated no longer make the values as globs which breaks my scripts in said scenarios.
Describe the solution you'd like
Add a --coerce-rest-into-globs and when passed to def and the annotation of rest is glob it will make values like true, false, 011 as globs instead of converting it into boolean or integer.
And game launchers that passes values for rest won't have extra quotations for "true", "false", "011" so when I saw before that rest without annotation left the values as glob and didn't break or error out when "true", "false", "011" i was very happy as it fixes said scenario.
As it no longer covers my scenario can i get a fix for this pretty please?
#!/usr/bin/env nu
export def main --wrapped [--my-flag: string ...rest] {
$rest | each { {type: ($in | describe) value: $in} } | print
print $"my flag: ($my_flag)"
}
Now if both script or command have the same flag the first one will consume it instead. For that reason I can't rely on --wrapped. As chaining two nushell script with the same flag wont behave correctly.
Oh i guess it can either be glob or string i was mentioning glob because it was the previous behaviour. And since glob didn't modify the values like '011' i was okay with globs. I understand that the pr intention was to make so that not annotated rest would convert it into nushell data types which understandable which is why I wanted something like a flag to bring back the other behaviour.
Futhermore, I believe --wrapped wont be needed anymore in the future as there is --. As we can see the $my_flag has the correct value of hello and the other --my-flag is correctly not consumed.
For example:
./script3.nu--my-flag=hello--some-other-command--more-commands--my-flag=goodbye╭───┬────────┬────────────────────╮│# │ type │ value │├───┼────────┼────────────────────┤│0│string│some-other-command││1│string│--││2│string│more-commands││3│string│--my-flag=goodbye│╰───┴────────┴────────────────────╯myflag:hello
Unless there is a usage of --wrapped where -- does not solve that i missed though i believe --wrapped was needed because -- was not a thing before.
Or we can reuse and make --wrapped behave like a normal def (where -- works) but when --wrapped is included we make rest values coerced to either string or glob but passing true or "true" won't make an error and force coercion and not have it do any conversions and what i mean by that is to make sure so that 011 or "011" dont get converted into 11.
Yes, --wrapped was because -- did not exist. I'm not sure it's necessary anymore since we have -- now. What is the problem with just using --? I'd probably fix it if there were a problem with it.
There is no problem with -- I was just saying that if we were going to eventually drop --wrapped, instead we could reuse it (if the flag name is appropiate for this feature) so when rest: string is defined when doing script.nu true false 011 the values passed will be as is (string): true ,false, 011 and no error of incorrect data type which is currently doing without --wrapped.
I do need something like that because game launchers won't quote true, 011 and quoting true -> "true" does not help when is being passed to a nushell script as it will still complain about incorrect data type.
I do need to hear your thoughts when you are available whether this feature will be worked on as currently I don't know what to do, whether I should wait for the feature or roll back to a previous commit while the feature is worked on.
I guess I can use that technique to forward them as "true", "false" and "011" so like cmd.nu true false 011 will pass to exec script.nu \"true\", \"false\" and \"011". I guess I can make use of this but some stuff will be broken. For example i can think of if exec receives script.nu where script.nu has some user defined flags script.nu \"--my-flag=hi\" this wont be recognised as a proper flag but I guess i could parse it myself and check whether it is a flag and remove the literal quotation but this is still a unconvinient workaround compared to having nushell just have rest: string and have something like def --coerce so true, false and 011 does not cause any issues.
For a proper solution in the future can we have something that I don't have to use a workaround like def --coerce or something that I was trying to convey?
I'm sorry if i was confusing I just realized this myself but essentially I just want -- to work with --wrapped without rest consuming -- as a rest item that it does currently.
The problem is that --wrapped is there to wrap external commands, and some of those use the -- themselves, so if you don't put it in ...$rest, it won't work. For example
cargo run --target=aarch64-unknown-linux-gnu -- arg1 arg2
Uses the -- to separate compiler flags from command arguments. If I want to use that command inside nushell with --wrapped, I need the -- or it won't work properly.
Activity
fdncred commentedon Jun 12, 2026
You can quote your parameters to coerce them into globs.
Skyrocket1653 commentedon Jun 12, 2026
that wont work if used as a script
Skyrocket1653 commentedon Jun 12, 2026
And game launchers that passes values for rest won't have extra quotations for
"true","false","011"so when I saw before thatrestwithout annotation left the values as glob and didn't break or error out when"true","false","011"i was very happy as it fixes said scenario.As it no longer covers my scenario can i get a fix for this pretty please?
fdncred commentedon Jun 12, 2026
You could also use def --wrapped
I'm not sure what the point of having globs because external programs do not understand nushell globs necessarily.
Skyrocket1653 commentedon Jun 12, 2026
When using --wrapped i can no longer do
--:Now if both script or command have the same flag the first one will consume it instead. For that reason I can't rely on
--wrapped. As chaining two nushell script with the same flag wont behave correctly.fdncred commentedon Jun 12, 2026
We could revert #18372 but I'm not clear why you want globs since strings are what is used to pass to externals.
Skyrocket1653 commentedon Jun 12, 2026
Oh i guess it can either be glob or string i was mentioning glob because it was the previous behaviour. And since glob didn't modify the values like '011' i was okay with globs. I understand that the pr intention was to make so that not annotated rest would convert it into nushell data types which understandable which is why I wanted something like a flag to bring back the other behaviour.
Skyrocket1653 commentedon Jun 12, 2026
Futhermore, I believe
--wrappedwont be needed anymore in the future as there is--. As we can see the $my_flag has the correct value ofhelloand the other--my-flagis correctly not consumed.For example:
Unless there is a usage of
--wrappedwhere--does not solve that i missed though i believe--wrappedwas needed because--was not a thing before.Or we can reuse and make
--wrappedbehave like a normaldef(where--works) but when--wrappedis included we makerestvalues coerced to either string or glob but passingtrueor"true"won't make an error and force coercion and not have it do any conversions and what i mean by that is to make sure so that011or"011"dont get converted into11.fdncred commentedon Jun 12, 2026
Yes,
--wrappedwas because--did not exist. I'm not sure it's necessary anymore since we have--now. What is the problem with just using--? I'd probably fix it if there were a problem with it.Skyrocket1653 commentedon Jun 12, 2026
There is no problem with
--I was just saying that if we were going to eventually drop--wrapped, instead we could reuse it (if the flag name is appropiate for this feature) so whenrest: stringis defined when doingscript.nu true false 011the values passed will be as is (string):true,false,011and no error of incorrect data type which is currently doing without--wrapped.I do need something like that because game launchers won't quote
true,011and quotingtrue->"true"does not help when is being passed to a nushell script as it will still complain about incorrect data type.Skyrocket1653 commentedon Jun 12, 2026
I do need to hear your thoughts when you are available whether this feature will be worked on as currently I don't know what to do, whether I should wait for the feature or roll back to a previous commit while the feature is worked on.
fdncred commentedon Jun 12, 2026
You could always wrap them in quotes yourself.
Skyrocket1653 commentedon Jun 12, 2026
I guess I can use that technique to forward them as
"true","false"and"011"so likecmd.nu true false 011will pass toexecscript.nu\"true\",\"false\"and\"011". I guess I can make use of this but some stuff will be broken. For example i can think of ifexecreceivesscript.nuwherescript.nuhas some user defined flagsscript.nu \"--my-flag=hi\"this wont be recognised as a proper flag but I guess i could parse it myself and check whether it is a flag and remove the literal quotation but this is still a unconvinient workaround compared to having nushell just haverest: stringand have something likedef --coercesotrue,falseand011does not cause any issues.For a proper solution in the future can we have something that I don't have to use a workaround like
def --coerceor something that I was trying to convey?Skyrocket1653 commentedon Jun 12, 2026
I'm sorry if i was confusing I just realized this myself but essentially I just want
--to work with--wrappedwithout rest consuming--as a rest item that it does currently.Tyarel8 commentedon Jun 13, 2026
The problem is that
--wrappedis there to wrap external commands, and some of those use the--themselves, so if you don't put it in...$rest, it won't work. For exampleUses the
--to separate compiler flags from command arguments. If I want to use that command inside nushell with--wrapped, I need the--or it won't work properly.Also, it would be a unexpected footgun, since the purpose of the flag is to not do any parsing or special handling and treat everything as a string.
Skyrocket1653 commentedon Jun 13, 2026
Okay I've left
--wrappedhow it was and added another flag to do it--coerce.fixes a bug in the end-of-options functionality (#18408)