| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Removes a global variable from Kestrun shared state. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | Deletes a variable from the Kestrun global variable table. |
| | | 6 | | If the variable does not exist, no action is taken. |
| | | 7 | | .PARAMETER Server |
| | | 8 | | The Kestrun server instance. |
| | | 9 | | .PARAMETER Global |
| | | 10 | | If specified, the variable is removed from the global shared state. |
| | | 11 | | .PARAMETER Name |
| | | 12 | | Name of the variable to remove. |
| | | 13 | | .PARAMETER WhatIf |
| | | 14 | | Shows what would happen if the command runs. The command is not run. |
| | | 15 | | .PARAMETER Confirm |
| | | 16 | | Prompts you for confirmation before running the command. The command is not run unless you respond |
| | | 17 | | affirmatively. |
| | | 18 | | .EXAMPLE |
| | | 19 | | Remove-KrSharedState -Name "MyVariable" |
| | | 20 | | This removes the global variable "MyVariable". |
| | | 21 | | .NOTES |
| | | 22 | | This function is part of the Kestrun.SharedState module and is used to remove global variables. |
| | | 23 | | #> |
| | | 24 | | function Remove-KrSharedState { |
| | | 25 | | [KestrunRuntimeApi('Everywhere')] |
| | | 26 | | [CmdletBinding(defaultParameterSetName = 'Server', SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] |
| | | 27 | | [OutputType([bool])] |
| | | 28 | | param( |
| | | 29 | | [Parameter(ValueFromPipeline = $true, ParameterSetName = 'Server')] |
| | | 30 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 31 | | |
| | | 32 | | [Parameter(Mandatory = $true, ParameterSetName = 'Global')] |
| | | 33 | | [switch]$Global, |
| | | 34 | | |
| | | 35 | | [Parameter(Mandatory)] |
| | | 36 | | [string]$Name |
| | | 37 | | ) |
| | | 38 | | begin { |
| | 0 | 39 | | if (-not $Global.IsPresent) { |
| | | 40 | | # Ensure the server instance is resolved |
| | 0 | 41 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 42 | | } |
| | | 43 | | } |
| | | 44 | | process { |
| | 0 | 45 | | if ($Global.IsPresent) { |
| | | 46 | | # Remove from global store |
| | 0 | 47 | | if ($PSCmdlet.ShouldProcess("Global shared state variable '$Name'", "Remove")) { |
| | 0 | 48 | | return [Kestrun.SharedState.GlobalStore]::Remove($Name) |
| | | 49 | | } |
| | 0 | 50 | | return $false |
| | | 51 | | } |
| | | 52 | | # Remove from server instance |
| | 0 | 53 | | if ($PSCmdlet.ShouldProcess("Shared state variable '$Name' on server '$($Server.Name)'", "Remove")) { |
| | 0 | 54 | | return $Server.SharedState.Remove($Name) |
| | | 55 | | } |
| | 0 | 56 | | return $false |
| | | 57 | | } |
| | | 58 | | } |
| | | 59 | | |