Provide parser with path to script file executed by means of -File command line argument#12494
Provide parser with path to script file executed by means of -File command line argument#12494m5x wants to merge 5 commits intoPowerShell:masterfrom m5x:master
Conversation
…mmand line argument
vexx32
left a comment
There was a problem hiding this comment.
Code seems sound, nice work!
Can we add a test to verify this works and guard against regressions?
…tion.InvocationName contain proper values when running script by means of -File argument
|
Tests have been added. I also added one small change to use |
|
Sorry for the spacing around parentheses. I like to put spaces inside for better readability and I've been doing it so long that I type it automatically this way and sometimes forget to check and fix it when committing to other projects. I will fix it in next commit - should I add [Feature] prefix to the commit message again to comply with testing guidelines in case it is the last one of this PR? |
….Runspaces.Command class
|
Added the requested formatting and property docs changes. CodeFactor reports no more issues. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@m5x Please rebase to pass CIs. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
Is rebasing all that's blocking merge of this pull request? I have currently some other things I have to finish first but if I am the only one blocking this I'll try to find a time to rebase this weekend. |
|
It is a question for MSFT team - @daxian-dbw @anmenaga have you time to review the PR? |
|
Add @SteveL-MSFT and @rjmholt to review. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
Open PRs should not be assigned to milestone, so they are not assigned to the wrong milestone after they are merged. For backport consideration, use a |
|
Blocked on #12494 (comment); @SteveL-MSFT or the @PowerShell/powershell-committee need to advise on whether we want to make this change |
| commandProcessorBase = new CommandProcessor(functionInfo, executionContext, | ||
| _useLocalScope ?? false, fromScriptFile: false, sessionState: executionContext.EngineSessionState); | ||
| } | ||
| else if (ScriptPath != null) |
There was a problem hiding this comment.
| else if (ScriptPath != null) | |
| else if (ScriptPath is not null) |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
| param($Filename) | ||
| $testFilePath = Join-Path $testdrive $Filename | ||
| Set-Content -Path $testFilePath -Value '$MyInvocation.MyCommand.Name' | ||
| $observed = & $powershell -File $testFilePath -NoProfile -NoLogo |
There was a problem hiding this comment.
There was an intentional breaking change in PowerShell 7.2 related to powershell -File: when running on Windows, a file without .ps1 extension is not allowed to run using pwsh -File. So, the test won't work on Windows.
| } | ||
| else if (ScriptPath != null) | ||
| { | ||
| var scriptName = Path.GetFileName(ScriptPath); |
There was a problem hiding this comment.
The script (content of the file) could be using cmdlet binding (scriptBlock.UsesCmdletBinding being true), by having a param block defined. In that case, the code execution would fall into the if (scriptBlock.UsesCmdletBinding) block, right?
|
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment. |
PR Summary
Allow
System.Management.Automation.Runspaces.Commandoperating inIsScript = truemode to remember and pass on path to the script file and make use of this feature when executing script file passed as -File command line argument.PR Context
Fixes #4217