-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Change positional parameter for powershell.exe from -Command to -File #4019
Change positional parameter for powershell.exe from -Command to -File #4019
Conversation
@SteveL-MSFT You might find limiting that settting to just PowerShell files to be handy - especially for this repo e.g.:
Then VSCode will not mess with trailing whitespace on .cs and .resx files. |
You probably should fix the resx file to only include your intended change - the other whitespace changes do have a visible effect in the binary, which is probably fine, but should be in a different commit. In reply to: 308830296 [](ancestors = 308830296) |
{ | ||
string script = File.ReadAllText(filePath); | ||
c = new Command(script, isScript: true, useLocalScope: false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this set the exit code correctly? You don't have a test - you should add one as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add test
@@ -967,6 +851,122 @@ private void ParseExecutionPolicy(string[] args, ref int i, ref string execution | |||
executionPolicy = args[i]; | |||
} | |||
|
|||
private bool ParseFile(string[] args, ref int i, bool noexitSeen) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C# now supports local functions - that would make this a bit simpler because you wouldn't the parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making ParseFile a local function would make it inconsistent with similar methods like ParseCommand(), ParseFormat(), ParseExecutionPolicy(), etc...
Isn't this a breaking change? It should be documented in the release notes. |
… to execute. To align with POSIX so that things like shebang scripts work correctly, we are changing powershell.exe so that it treats unknown arguments (aka positional argument) as a file. This means that `powershell foo` will now attempt to use `foo` as a PowerShell script whereas previously `foo` would be treated as a command to execute. This doesn't affect existing usage of either `-File` nor `-Command`. Fixed tests that didn't explicitly use `-Command` parameter.
added test to validate exit code from script
18436cb
to
a7a2497
Compare
@lzybkr any other feedback, would like to get this into beta.3 since it's a breaking change and get the feedback |
Previously powershell.exe treated unknown arguments as a command line to execute. To align with POSIX so that things like shebang scripts work correctly, we are changing powershell.exe so that it treats unknown arguments (aka positional argument) as a file. This means that
powershell foo
will now attempt to usefoo
as a PowerShell script whereas previouslyfoo
would be treated as a command to execute. This doesn't affect existing usage of either-File
nor-Command
. Fixed tests that didn't explicitly use-Command
parameter.Note that some of the changes below for trailing whitespace was due to VSCode setting.
Fix #1103
Fix #3959