| | | 1 | | |
| | | 2 | | <# |
| | | 3 | | .SYNOPSIS |
| | | 4 | | Sets the Kestrun environment for the current PowerShell session. |
| | | 5 | | .DESCRIPTION |
| | | 6 | | Sets the Kestrun environment for the current PowerShell session. |
| | | 7 | | This affects how Kestrun behaves, for example in terms of error handling and logging. |
| | | 8 | | .PARAMETER Name |
| | | 9 | | The name of the environment to set. Valid values are 'Development', 'Staging', and 'Production'. |
| | | 10 | | .PARAMETER WhatIf |
| | | 11 | | Shows what would happen if the cmdlet runs. The cmdlet is not run. |
| | | 12 | | .PARAMETER Confirm |
| | | 13 | | Prompts you for confirmation before running the cmdlet. |
| | | 14 | | .OUTPUTS |
| | | 15 | | The name of the currently set environment after applying the change. |
| | | 16 | | .EXAMPLE |
| | | 17 | | Set-KrEnvironment -Name 'Development' |
| | | 18 | | Sets the Kestrun environment to 'Development'. |
| | | 19 | | This enables detailed error messages and logging for development purposes. |
| | | 20 | | .EXAMPLE |
| | | 21 | | Set-KrEnvironment -Name 'Production' |
| | | 22 | | Sets the Kestrun environment to 'Production'. |
| | | 23 | | This enables optimized settings for a production environment. |
| | | 24 | | #> |
| | | 25 | | function Set-KrEnvironment { |
| | | 26 | | [KestrunRuntimeApi('Everywhere')] |
| | | 27 | | [CmdletBinding(SupportsShouldProcess)] |
| | | 28 | | [OutputType([string])] |
| | | 29 | | param( |
| | | 30 | | [Parameter(Mandatory)] |
| | | 31 | | [ValidateSet('Auto', 'Development', 'Staging', 'Production')] |
| | | 32 | | [string]$Name |
| | | 33 | | ) |
| | 0 | 34 | | if ($PSCmdlet.ShouldProcess('Kestrun Environment', "Set -> $Name")) { |
| | 0 | 35 | | if ($Name -eq 'Auto') { |
| | 0 | 36 | | [Kestrun.Runtime.EnvironmentHelper]::ClearOverride() |
| | | 37 | | } else { |
| | 0 | 38 | | [Kestrun.Runtime.EnvironmentHelper]::SetOverrideName($Name) |
| | | 39 | | } |
| | 0 | 40 | | [Kestrun.Runtime.EnvironmentHelper]::Name |
| | | 41 | | } |
| | | 42 | | } |