-
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
Redirecting to a variable should be possible #20381
Redirecting to a variable should be possible #20381
Conversation
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs
Outdated
Show resolved
Hide resolved
7b91172
to
d2b7909
Compare
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.
Some very minor style nits, other than that looks great! Very excited for this change ❤️
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs
Outdated
Show resolved
Hide resolved
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
fd180eb
to
0fcf9b1
Compare
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
0fcf9b1
to
8ab03ca
Compare
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
Update test to check for experimental feature status. Set-Variable will still have the -append parameter, but if used when the experimental feature is disabled, a parameter binding error will result.
This reverts commit 8b34af1.
Co-authored-by: Ilya <darpa@yandex.ru>
Update Set-Variable -Append to be correct when -name and -value are used. Add tests for the new behavior in Set-Variable.
Co-authored-by: Ilya <darpa@yandex.ru>
Add tests to validate.
8ab03ca
to
68f8ed3
Compare
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs
Outdated
Show resolved
Hide resolved
// Now, We can take what ever has been set if PSDefaultParameterValues | ||
// Unicode is still the default, but now may be overridden | ||
// determine whether we're trying to set a variable by inspecting the file path | ||
// if we can determine that it's a variable, we'll use Set-Variable rather than Out-File |
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.
Just a note and not something you need to change, but it seems in the future, it would make more sense to have Out-Provider
and have the provider subsystem determine which provider receives it rather than hardcoding to specific cases here
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.
I did think about that when I put this together and thought that the scenarios for redirection to something other than filesystem or variable were pretty limited, so I took this approach.
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.
I agree that a smaller change now makes sense. Created #23794 to capture this.
…cOps.cs Co-authored-by: Steve Lee <slee@microsoft.com>
Co-authored-by: Steve Lee <slee@microsoft.com>
…cOps.cs Co-authored-by: Steve Lee <slee@microsoft.com>
📣 Hey @JamesWTruher, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
PR Summary
There are a number of situations where it would be very convenient to redirect data to a variable using the
variable:name
syntax. This PR provides this behavior by inspecting the target of the redirection and if it uses the variable provider will callSet-Variable
rather thanOut-File
.With this PR the following scenarios are possible:
This could prove very helpful to some logging scenarios as well.
Append is also supported via
>>
and redirecting multiple streams to multiple targets, based on the stream number:
Lastly, object-ness is preserved:
This is not to say that redirection to a variable should take the place of assignment, but it does enable some new scenarios.
the current behavior when redirecting to a variable is an error (because redirection is implemented via
Out-File
):PR Context
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.PSRedirectToVariable
(which runs in a different PS Host).