< Summary - Kestrun — Combined Coverage

Information
Class: Public.Server.Remove-KrServer
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Remove-KrServer.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 51
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Remove-KrServer.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Removes a Kestrun server instance.
 4    .DESCRIPTION
 5        This function stops and destroys a Kestrun server instance with the specified name.
 6    .PARAMETER Name
 7        The name of the Kestrun server instance to remove.
 8    .PARAMETER Force
 9        If specified, the server will be stopped and destroyed without confirmation.
 10    .EXAMPLE
 11        Remove-KrServer -Name "MyKestrunServer"
 12        Removes the specified Kestrun server instance.
 13    .EXAMPLE
 14        Remove-KrServer -Name "MyKestrunServer" -Force
 15        Removes the specified Kestrun server instance without confirmation.
 16    .NOTES
 17        This function is designed to be used in the context of a Kestrun server management.
 18#>
 19function Remove-KrServer {
 20    [KestrunRuntimeApi('Definition')]
 21    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
 22    [CmdletBinding()]
 23    [OutputType([Kestrun.Hosting.KestrunHost])]
 24    param(
 25        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 26        [string]$Name,
 27        [Parameter()]
 28        [switch]$Force
 29    )
 30    process {
 031        if ( [Kestrun.KestrunHostManager]::Contains($Name) ) {
 032            if ($Force) {
 033                if ([Kestrun.KestrunHostManager]::IsRunning($Name)) {
 034                    [Kestrun.KestrunHostManager]::Stop($Name)
 35                }
 036                [Kestrun.KestrunHostManager]::Destroy($Name)
 37            } else {
 038                $confirm = Read-Host "Server '$Name' is running. Do you want to stop and destroy the previous instance? 
 039                if ($confirm -notin @('Y', 'y')) {
 040                    Write-Warning 'Operation cancelled by user.'
 041                    exit 1
 42                }
 043                if ([Kestrun.KestrunHostManager]::IsRunning($Name)) {
 044                    [Kestrun.KestrunHostManager]::Stop($Name)
 45                }
 046                [Kestrun.KestrunHostManager]::Destroy($Name)
 47            }
 48        }
 49    }
 50}
 51

Methods/Properties

Remove-KrServer()