Add -PassThru parameter to Set-Clipboard (#13713)

This commit is contained in:
Thomas Nieto
2021-07-22 10:17:53 -07:00
committed by GitHub
parent 0002f7e8be
commit 7777afc005
2 changed files with 43 additions and 0 deletions
@@ -17,6 +17,7 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
[Cmdlet(VerbsCommon.Set, "Clipboard", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium, HelpUri = "https://go.microsoft.com/fwlink/?LinkId=2109826")]
[Alias("scb")]
[OutputType(typeof(string))]
public class SetClipboardCommand : PSCmdlet
{
private readonly List<string> _contentList = new();
@@ -37,6 +38,12 @@ namespace Microsoft.PowerShell.Commands
[Parameter]
public SwitchParameter Append { get; set; }
/// <summary>
/// Gets or sets if the values sent down the pipeline.
/// </summary>
[Parameter]
public SwitchParameter PassThru { get; set; }
/// <summary>
/// This method implements the BeginProcessing method for Set-Clipboard command.
/// </summary>
@@ -53,6 +60,11 @@ namespace Microsoft.PowerShell.Commands
if (Value != null)
{
_contentList.AddRange(Value);
if (PassThru)
{
WriteObject(Value);
}
}
}
@@ -51,5 +51,36 @@ Describe 'Clipboard cmdlet tests' -Tag CI {
$text | Set-Clipboard
Get-Clipboard -Raw | Should -BeNullOrEmpty
}
It 'Set-Clipboard should not return object' {
$result = 'hello' | Set-Clipboard
$result | Should -BeNullOrEmpty
}
It 'Set-Clipboard -PassThru returns single object with -Append = <Append>' -TestCases @(
@{ Append = $false }
@{ Append = $true }
){
param ($append)
$params = @{ PassThru = $true; Append = $append }
Set-Clipboard -Value 'world'
$result = 'hello' | Set-Clipboard @params
$result | Should -BeExactly 'hello'
}
It 'Set-Clipboard -PassThru returns multiple objects with -Append = <Append>' -TestCases @(
@{ Append = $false }
@{ Append = $true }
){
param ($append)
$params = @{ PassThru = $true; Append = $append }
Set-Clipboard -Value 'world'
$result = 'hello', 'world' | Set-Clipboard @params
$result | Should -BeExactly @('hello', 'world')
}
}
}