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
Add NoNewLine switch for Out-String cmdlet #5056
Conversation
2fbea3c
to
38a2f00
Compare
_buffer.AppendLine(s); | ||
} | ||
} | ||
|
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 remove extra line.
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.
Done as suggested
@@ -124,7 +143,17 @@ private void OnWriteLine(string s) | |||
if (_stream) | |||
this.WriteObject(s); | |||
else |
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 add braces 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.
Added braces as suggested
set | ||
{ | ||
_suppressNewline = value; | ||
} |
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 use one line formatting as above.
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.
Thanks for pointing that out. Done!
/// False to add a newline to the end of the output string, true if not. | ||
/// </summary> | ||
[Parameter] | ||
public SwitchParameter NoNewline |
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 put NoNewLine
and Sream
parameters in different parameter sets as discussed in the Issue.
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.
Done. I have named the ParameterSets as NonStreamFormatting and StreamFormatting for want of a better name. Do suggest one if this is bad :)
I've also fixed-up the commit instead of adding a new one to keep it clean. Let me know if that is an inconvenience.
@@ -45,4 +45,14 @@ Describe "Out-String" -Tags "CI" { | |||
|
|||
$streamoutputlength | Should BeLessThan $nonstreamoutputlength | |||
} | |||
|
|||
It "Should not print a newline when the nonewline switch is used" { | |||
$testArray = "a", " b" |
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.
Why we use space? I'd prefer to remove.
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 was not sure what example to give and hence followed the one in
It "Should accumulate the strings and returns them as a single string"
Will remove the space as suggested
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.
removed the space
d3a59c3
to
f17122a
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.
LGTM.
We just need to make sure the documentation is updated to include the new parameter. |
/// <summary> | ||
/// False to add a newline to the end of the output string, true if not. | ||
/// </summary> | ||
[Parameter(ParameterSetName="NonStreamFormatting")] |
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'd prefer "NoNewlineFormatting".
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.
Nice. changing it now
|
||
It "Should not print a newline when the nonewline switch is used" { | ||
$testArray = "a", "b" | ||
$testArray | Out-String -NoNewLine | Should Be "ab" |
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 add the test for default parameter set:
$testArray | Out-String | Should Be "ab"
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.
If i am not wrong, this is the test for the default parameter set wherein newlines are added to the output. Is my understanding correct?
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.
Thanks! Yes, correct.
Closed.
It "Should preserve embedded newline when the nonewline switch is used" { | ||
$testArray = "a$nl", "b" | ||
$testArray | Out-String -NoNewLine | Should Be "a$($nl)b" | ||
} | ||
} |
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 think we should a test that Stream
and NoNewLine
in different parameter sets:
{$testarray | Out-String -NoNewLine -Stream } | ShouldBeErrorId "....."
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.
Sure. I was a bit unsure how to go about doing that. Thanks for helping out!
f17122a
to
cfd5ebd
Compare
|
||
It "Should preserve embedded newline when the nonewline switch is used" { | ||
$testArray = "a$nl", "b" | ||
$testArray | Out-String -NoNewLine | Should Be "a$($nl)b" |
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 replace $($nl)
with ${nl}
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.
Sure. Done :)
cfd5ebd
to
eb5cb2a
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.
@raghav710 Thanks for your contribution! Hope to see you around more.
One side note: It's recommended to push new commits to address comments instead of squashing new fixes into the existing commit. In this way, the change history is preserved and it's very helpful for code reviews.
@daxian-dbw Thanks for the note. Will follow that henceforth during code reviews. As an aside, do you think it is good to squash the commits after approval as that would keep the history clean in case there were multiple code comments. |
@raghav710 We want keep the history while we review. Then we usually Squash and Merge for simple changes. But if the code is very complex, tricky and add big feature we keep all commits. |
@mklement0 We merged the PR but we can always bring Out-String and Out-File into line until RTM. |
Yaay! |
Fix #3684.
First PS pull request {insert nervous emoji}
Mostly adapted from the -NoNewLine changes for Out-File