diff --git a/src/functions/private/Get-ContextVaultKeyPair.ps1 b/src/functions/private/Get-ContextVaultKeyPair.ps1 index e3820415..9a5df636 100644 --- a/src/functions/private/Get-ContextVaultKeyPair.ps1 +++ b/src/functions/private/Get-ContextVaultKeyPair.ps1 @@ -32,7 +32,7 @@ } process { - $vaultObject = Set-ContextVault -Name $Vault + $vaultObject = Set-ContextVault -Name $Vault -PassThru $shardPath = Join-Path -Path $vaultObject.Path -ChildPath $script:Config.ShardFileName $fileShard = Get-Content -Path $shardPath $machineShard = [System.Environment]::MachineName diff --git a/src/functions/public/Rename-Context.ps1 b/src/functions/public/Rename-Context.ps1 index 87fdb1ac..abb77a85 100644 --- a/src/functions/public/Rename-Context.ps1 +++ b/src/functions/public/Rename-Context.ps1 @@ -61,7 +61,11 @@ # The name of the vault containing the context. [Parameter()] [ArgumentCompleter({ Complete-ContextVaultName @args })] - [string] $Vault + [string] $Vault, + + # Pass the context through the pipeline. + [Parameter()] + [switch] $PassThru ) begin { @@ -81,7 +85,7 @@ } if ($PSCmdlet.ShouldProcess("Renaming context '$ID' to '$NewID' in vault '$Vault'")) { - $context | Set-Context -ID $NewID -Vault $Vault + $context | Set-Context -ID $NewID -Vault $Vault -PassThru:$PassThru Remove-Context -ID $ID -Vault $Vault } } diff --git a/src/functions/public/Set-Context.ps1 b/src/functions/public/Set-Context.ps1 index 41a09944..e9c72537 100644 --- a/src/functions/public/Set-Context.ps1 +++ b/src/functions/public/Set-Context.ps1 @@ -67,7 +67,11 @@ function Set-Context { # The name of the vault to store the context in. [Parameter(Mandatory)] [ArgumentCompleter({ Complete-ContextVaultName @args })] - [string] $Vault + [string] $Vault, + + # Pass the context through the pipeline. + [Parameter()] + [switch] $PassThru ) begin { @@ -76,7 +80,7 @@ function Set-Context { } process { - $vaultObject = Set-ContextVault -Name $Vault + $vaultObject = Set-ContextVault -Name $Vault -PassThru $vaultObject | Format-List | Out-String -Stream | ForEach-Object { Write-Verbose "[$stackPath] $_" } if ($context -is [System.Collections.IDictionary]) { @@ -119,7 +123,9 @@ function Set-Context { Set-Content -Path $contextPath -Value $content } - Get-Context -ID $ID -Vault $Vault + if ($PassThru) { + Get-Context -ID $ID -Vault $Vault + } } end { diff --git a/src/functions/public/Vault/Reset-ContextVault.ps1 b/src/functions/public/Vault/Reset-ContextVault.ps1 index dc4b6c81..f7f49618 100644 --- a/src/functions/public/Vault/Reset-ContextVault.ps1 +++ b/src/functions/public/Vault/Reset-ContextVault.ps1 @@ -29,7 +29,11 @@ # The vault object to reset. [Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'As ContextVault')] - [ContextVault[]] $InputObject + [ContextVault[]] $InputObject, + + # Pass the context through the pipeline. + [Parameter()] + [switch] $PassThru ) begin { @@ -45,7 +49,7 @@ Write-Verbose "Resetting ContextVault [$($vault.Name)] at path [$($vault.Path)]" if ($PSCmdlet.ShouldProcess("ContextVault: [$($vault.Name)]", 'Reset')) { Remove-ContextVault -Name $($vault.Name) -Confirm:$false - Set-ContextVault -Name $($vault.Name) + Set-ContextVault -Name $($vault.Name) -PassThru:$PassThru Write-Verbose "ContextVault [$($vault.Name)] reset successfully." } } diff --git a/src/functions/public/Vault/Set-ContextVault.ps1 b/src/functions/public/Vault/Set-ContextVault.ps1 index 59e6e18f..1e74cc06 100644 --- a/src/functions/public/Vault/Set-ContextVault.ps1 +++ b/src/functions/public/Vault/Set-ContextVault.ps1 @@ -25,7 +25,11 @@ function Set-ContextVault { # The name of the vault to create or update. [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] [ArgumentCompleter({ Complete-ContextVaultName @args })] - [string[]] $Name + [string[]] $Name, + + # Pass the context through the pipeline. + [Parameter()] + [switch] $PassThru ) begin { @@ -52,7 +56,9 @@ function Set-ContextVault { } } - [ContextVault]::new($vaultName, $vaultPath) + if ($PassThru) { + [ContextVault]::new($vaultName, $vaultPath) + } } } diff --git a/tests/ContextVaults.Tests.ps1 b/tests/ContextVaults.Tests.ps1 index fa1e0fd4..c192febf 100644 --- a/tests/ContextVaults.Tests.ps1 +++ b/tests/ContextVaults.Tests.ps1 @@ -38,7 +38,7 @@ Describe 'ContextVault' { } It 'Should create a new vault with a single name parameter' { - $result = Set-ContextVault -Name 'test-vault1' + $result = Set-ContextVault -Name 'test-vault1' -PassThru $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [ContextVault] $result.Name | Should -Be 'test-vault1' @@ -46,7 +46,7 @@ Describe 'ContextVault' { } It 'Should create multiple vaults from array parameter' { - $results = Set-ContextVault -Name 'test-vault2', 'test-vault3' + $results = Set-ContextVault -Name 'test-vault2', 'test-vault3' -PassThru $results | Should -HaveCount 2 $results | ForEach-Object { $_ | Should -BeOfType [ContextVault] } $results[0].Name | Should -Be 'test-vault2' @@ -54,7 +54,7 @@ Describe 'ContextVault' { } It 'Should accept pipeline input for vault creation' { - $results = 'test-pipeline1', 'test-pipeline2' | Set-ContextVault + $results = 'test-pipeline1', 'test-pipeline2' | Set-ContextVault -PassThru $results | Should -HaveCount 2 $results | ForEach-Object { $_ | Should -BeOfType [ContextVault] } $results.Name | Should -Contain 'test-pipeline1' @@ -208,7 +208,7 @@ Describe 'ContextVault' { It 'Should support pipeline operations with variables' { $testVaults = @('pipeline-var1', 'pipeline-var2') - $results = $testVaults | Set-ContextVault + $results = $testVaults | Set-ContextVault -PassThru $results | Should -HaveCount 2 $getResults = Get-ContextVault -Name $testVaults