-
Notifications
You must be signed in to change notification settings - Fork 503
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
pwsh
does not support -Command
positionals, is incompatible with intended set shell
and positional-arguments
usage
#1592
Comments
This isn't necessarily a bug in
https://github.com/yarnpkg/berry/tree/master/packages/yarnpkg-shell#yarnpkgshell
Not suggesting |
First, thanks for looking into the issue so deeply. It is much appreciated. 😃 But |
I stand corrected, you're right. For open-source, I need a justfile that will work for most strangers wanting to contribute. My goal is to create a justfile that will work with zero or minimal effort, and hopefully zero modification since it's versioned by git.
Do you know of one on scoop? I can't find one. It doesn't have I think Git for Windows doesn't put the bundled I tried a conditional |
I'm pretty sure Git for Windows/Git Bash does put their Open Source Projects, that is a tough one...
I was about to create my own |
Yeah, it's an option with Git for Windows. Github Desktop doesn't offer the option.
For open source, the issue is mostly 4 factors:
Asking someone to install They probably already have git for windows, but without sh on the path. The issue is, if someone googles "How do I get |
To be honest if the setup is too tough for a developer then they may not be qualified to contribute. That is a very broad over simplification of course. And eliminating all reasonable barriers to entry should be a goal. But it is tough if the project isn't POSIX only or Windows only. The simple confusion of mixed platform parts (Windows batch files and POSIX shell scripts, etc.) can be very confusing to many who've only ever had experience with one platform. No matter what platform that is. It really is a tough problem. |
Or if they're qualified then they can spend their time on any number of projects, and may focus on one with a smoother on-ramp. You have to make things smooth for people if you want them to contribute. |
I completely agreed with you when I said
|
@cspotcode Thanks so much for explaining this in depth! It sounds like it would be pretty hard to provide useful and consistent behavior for powershell. It sounds like, for powershell, we would need to both pass arguments to command blocks, and quote them: & { echo $args.count } "foo" "bar" "baz" |
I’m not entirely certain I’ve understood correctly, but it seems to me that script blocks like the one in your example would be enough to provide consistent behaviour; only the arguments need to be escaped for PowerShell, which means adding backticks before a fixed set of characters. That would provide the correct list of arguments and count within the block as well as avoid evaluating each argument as PowerShell. |
Looking through various issues, I see a misunderstanding of how
pwsh -Command
accepts positionals. Unfortunately, it appears to accept them but actually does not (explained below) which makes it incompatible with the intended usage ofset shell
andset positional-arguments
.PowerShell Core · Issue #1554
Make
positional-arguments
default to true next edition · Issue #1367#1050 (comment)
That assessment is perfectly understandable, but the truth is a bit different.
powershell -Command
does not accept positional arguments at all! Rather, it interprets all positional arguments as being parts of a single command.A summary of the issues:
$@
,$args
, is emptyBash example for comparison
When we do:
bash is (roughly) executing "echo $1" as if it were a script named
foo
passed 2 positionals:bar
andbaz
$0
isfoo
$1
isbar
$2
isbaz
$@
is a bash array containingbar
andbaz
There is clear separation between the command and the positionals.
because the length of the
$@
array is 2.Powershell is not like that
Powershell does not behave like bash at all. To illustrate, we'll do the exact same thing we just did in bash, ported to powershell, replacing
${#}
with powershell equivalent$args.count
:Powershell does not put
foo bar baz
into an args array and pass it to the script. Rather, the positionals are part of the command.So it executes this line of code:
echo $args.count foo bar baz
This means powershell is not compatible with intended usage of
positional-arguments
, unless you want the recipe name and all positionals to be evaluated as powershell syntax.To get behavior akin to bash, you might try wrapping your command in a script block, making your recipe incompatible with bash:
This powershell syntax:
will output
3
because positionals after the script block have been passed to the block as$args
, equivalent to$@
Note that this still breaks for empty strings.
It also evaluates everything as powershell syntax, because it is all part of the command.
or passing to an external executable:
A more concrete example:
The text was updated successfully, but these errors were encountered: