mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add -PassThru parameter to Set-Clipboard (#13713)
This commit is contained in:
+12
@@ -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')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user