Skip to content

Provide parser with path to script file executed by means of -File command line argument - #12494

Closed
Martin Dvořák (m5x) wants to merge 5 commits into
PowerShell:masterfrom
m5x:master
Closed

Martin Dvořák (m5x) wants to merge 5 commits into
PowerShell:masterfrom
m5x:master

Conversation

@m5x

Copy link
Copy Markdown

PR Summary

Allow System.Management.Automation.Runspaces.Command operating in IsScript = true mode 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

@msftclas

Microsoft Contribution License Agreements (msftclas) commented Apr 25, 2020 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code seems sound, nice work!

Can we add a test to verify this works and guard against regressions?

@iSazonov Ilya (iSazonov) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests.

@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Apr 26, 2020
@iSazonov Ilya (iSazonov) added this to the 7.1.0-preview.3 milestone Apr 26, 2020
@m5x

Copy link
Copy Markdown
Author

Tests have been added. I also added one small change to use ExternalScriptInfo for scripts with known path (i.e. scripts started with -File argument) and thus provide proper values in $MyInvocation special variable even for scripts without .ps1 extension.

@m5x

Copy link
Copy Markdown
Author

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?

@m5x

Copy link
Copy Markdown
Author

Added the requested formatting and property docs changes. CodeFactor reports no more issues.

@ghost ghost added the Review - Needed The PR is being reviewed label May 27, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@iSazonov

Copy link
Copy Markdown
Collaborator

Martin Dvořák (@m5x) Please rebase to pass CIs.

@ghost ghost removed the Review - Needed The PR is being reviewed label Jul 23, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label Jul 30, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@m5x

Copy link
Copy Markdown
Author

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.

@iSazonov

Copy link
Copy Markdown
Collaborator

It is a question for MSFT team - Dongbo Wang (@daxian-dbw) Andrew (@anmenaga) have you time to review the PR?

@ghost ghost removed the Review - Needed The PR is being reviewed label Aug 1, 2020
@daxian-dbw

Copy link
Copy Markdown
Member

Add Steve Lee (@SteveL-MSFT) and Rob Holt (@rjmholt) to review.
Steve Lee (@SteveL-MSFT) You marked the issue "by design" in #4217 (comment), can you please review this PR and the subsequent comments in that issue to see if we want to accept this PR? Also would the change of design cause any breaking change?

@ghost ghost added the Review - Needed The PR is being reviewed label Aug 11, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@SteveL-MSFT Steve Lee (SteveL-MSFT) added this to the 7.2-Consider milestone Dec 9, 2020
@ghost ghost removed this from the 7.2-Consider milestone Dec 9, 2020
@ghost

Copy link
Copy Markdown

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 backport label.

@rjmholt

Copy link
Copy Markdown
Collaborator

Blocked on #12494 (comment); Steve Lee (@SteveL-MSFT) or the @PowerShell/powershell-committee need to advise on whether we want to make this change

@ghost ghost removed the Review - Needed The PR is being reviewed label Dec 10, 2020
commandProcessorBase = new CommandProcessor(functionInfo, executionContext,
_useLocalScope ?? false, fromScriptFile: false, sessionState: executionContext.EngineSessionState);
}
else if (ScriptPath != null)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if (ScriptPath != null)
else if (ScriptPath is not null)

@ghost ghost added the Review - Needed The PR is being reviewed label Dec 18, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@ghost ghost removed the Review - Needed The PR is being reviewed label Sep 15, 2021
@ghost ghost added the Review - Needed The PR is being reviewed label Sep 23, 2021
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

param($Filename)
$testFilePath = Join-Path $testdrive $Filename
Set-Content -Path $testFilePath -Value '$MyInvocation.MyCommand.Name'
$observed = & $powershell -File $testFilePath -NoProfile -NoLogo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels Jan 18, 2022
@ghost ghost added the Stale label Feb 3, 2022
@ghost

Copy link
Copy Markdown

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.

@ghost ghost closed this Feb 13, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Stale Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept

Projects

None yet

10 participants