-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Tee-Object: add -Encoding parameter
#14539
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
Tee-Object: add -Encoding parameter
#14539
Conversation
…polley/PowerShell into Add--Encoding-parameter-for-Tee-Object
-Encoding parameter-Encoding parameter
…polley/PowerShell into Add--Encoding-parameter-for-Tee-Object
…polley/PowerShell into Add--Encoding-parameter-for-Tee-Object
-Encoding parameter-Encoding parameter
iSazonov
left a comment
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.
Please fix CIs.
test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Modules/Microsoft.PowerShell.Utility/Tee-Object.Tests.ps1
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Tee-Object.cs
Outdated
Show resolved
Hide resolved
iSazonov
left a comment
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.
@rpolley Please look test fails.
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Tee-Object.cs
Outdated
Show resolved
Hide resolved
| /// <summary> | ||
| /// Sets the encoding to use when writing the file. | ||
| /// </summary> | ||
| [Parameter(Mandatory = 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.
Please revert - I was wrong.
| } | ||
|
|
||
| // passthrough Encoding parameter | ||
| _commandWrapper.AddNamedParameter("Encoding", Encoding); |
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.
This doesn't work for Tee-Object -Variable because we assign Encoding parameter to Set-Variable cmdlet. Please see previous
PowerShell/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Tee-Object.cs
Lines 117 to 121 in b303c2f
| // variable parameter set | |
| _commandWrapper.Initialize(Context, "set-variable", typeof(SetVariableCommand)); | |
| _commandWrapper.AddNamedParameter("name", _variable); | |
| // Can't use set-var's passthru because it writes the var object to the pipeline, we want just | |
| // the values to be written |
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.
Didn't even notice this, thanks. I updated it so that the Encoding parameter is only used for the File and LiteralFile parameter sets.
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Tee-Object.cs
Outdated
Show resolved
Hide resolved
| ) { | ||
| param($Encoding) | ||
| $teefile = $testfile | ||
| Write-Output -InputObject teeobjecttest3 | Tee-Object -FilePath $teefile -Encoding $Encoding |
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.
Really the test doesn't check encoding because write ASCII only.
Please see Verifies -Tail with content that uses an explicit/implicit encoding from Get-Content.Tests.ps1 . We could use the same string with native chars instead of teeobjecttest3.
This reverts commit 3890059.
Co-authored-by: Ilya <darpa@yandex.ru>
|
@rpolley Please look CodeFactor and CI issues. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
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) |
|
We need to open doc issue. |
|
@iSazonov This was documented in MicrosoftDocs/PowerShell-Docs#7902 |
|
🎉 Handy links: |
PR Summary
Fix #11104.
Adds a new -Encoding parameter to
Tee-Objectthat controls what text encoding to use for the output file. If not provided, the cmdlet behaves as before and uses the default encoding.PR Context
Most cmdlets that deal with text file IO have an
-Encodingparameter that tells the cmdlet which encoding to use when reading/writing the file. However,Tee-Objectdoes not. This pull request adds this functionality. Closes #11104.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.