< Summary - Kestrun — Combined Coverage

Information
Class: Public.Service.Set-KrServiceDescriptor
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Service/Set-KrServiceDescriptor.ps1
Tag: Kestrun/Kestrun@09cad9a8fdafda7aca15f5f5e888b4bbcc8f0674
Line coverage
83%
Covered lines: 56
Uncovered lines: 11
Coverable lines: 67
Total lines: 187
Line coverage: 83.5%
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 03/26/2026 - 03:54:59 Line coverage: 83.5% (56/67) Total lines: 187 Tag: Kestrun/Kestrun@844b5179fb0492dc6b1182bae3ff65fa7365521d

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Service/Set-KrServiceDescriptor.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Updates a Service.psd1 descriptor file.
 4.DESCRIPTION
 5    Updates Description, Version, EntryPoint, ServiceLogPath, and PreservePaths values in Service.psd1.
 6    Name is immutable and cannot be changed by this cmdlet.
 7.PARAMETER Path
 8    Descriptor path. Accepts either a descriptor file path or a directory path.
 9    When a directory path is provided, Service.psd1 is appended automatically.
 10.PARAMETER Description
 11    New description value.
 12.PARAMETER Version
 13    New version value compatible with System.Version.
 14.PARAMETER EntryPoint
 15    New entry point path value.
 16.PARAMETER ServiceLogPath
 17    New default service log path.
 18.PARAMETER ClearServiceLogPath
 19    Removes ServiceLogPath from the descriptor.
 20.PARAMETER PreservePaths
 21    Replaces PreservePaths with a new list of relative file/folder paths.
 22.PARAMETER ClearPreservePaths
 23    Removes PreservePaths from the descriptor.
 24.PARAMETER WhatIf
 25    Shows what would happen if the cmdlet runs. The cmdlet is not executed.
 26.PARAMETER Confirm
 27    Prompts for confirmation before running the cmdlet.
 28.EXAMPLE
 29    Set-KrServiceDescriptor -Path .\Service.psd1 -Description 'Updated' -Version 1.2.1
 30#>
 31function Set-KrServiceDescriptor {
 32    [KestrunRuntimeApi('Everywhere')]
 33    [CmdletBinding(SupportsShouldProcess)]
 34    [OutputType([pscustomobject])]
 35    param(
 36        [Parameter()]
 37        [ValidateNotNullOrEmpty()]
 38        [string]$Path = 'Service.psd1',
 39
 40        [Parameter()]
 41        [string]$Description,
 42
 43        [Parameter()]
 44        [version]$Version,
 45
 46        [Parameter()]
 47        [string]$EntryPoint,
 48
 49        [Parameter()]
 50        [string]$ServiceLogPath,
 51
 52        [Parameter()]
 53        [string[]]$PreservePaths,
 54
 55        [Parameter()]
 56        [switch]$ClearServiceLogPath,
 57
 58        [Parameter()]
 59        [switch]$ClearPreservePaths
 60    )
 61
 162    $updateRequested = $PSBoundParameters.ContainsKey('Description') -or
 63    $PSBoundParameters.ContainsKey('Version') -or
 64    $PSBoundParameters.ContainsKey('EntryPoint') -or
 65    $PSBoundParameters.ContainsKey('ServiceLogPath') -or
 66    $PSBoundParameters.ContainsKey('PreservePaths') -or
 67    $ClearServiceLogPath -or
 68    $ClearPreservePaths
 69
 170    if (-not $updateRequested) {
 071        throw 'No updates requested. Specify one or more updatable fields.'
 72    }
 73
 174    if ($PSBoundParameters.ContainsKey('ServiceLogPath') -and $ClearServiceLogPath) {
 075        throw 'Cannot use -ServiceLogPath and -ClearServiceLogPath together.'
 76    }
 77
 178    if ($PSBoundParameters.ContainsKey('PreservePaths') -and $ClearPreservePaths) {
 079        throw 'Cannot use -PreservePaths and -ClearPreservePaths together.'
 80    }
 81
 182    $current = Get-KrServiceDescriptor -Path $Path
 83
 384    $nextDescription = if ($PSBoundParameters.ContainsKey('Description')) { $Description } else { $current.Description }
 185    $nextVersion = if ($PSBoundParameters.ContainsKey('Version')) {
 186        if ($null -eq $Version) {
 187            $null
 88        } else {
 189            $Version.ToString()
 90        }
 91    } else {
 192        $current.Version
 93    }
 394    $nextEntryPoint = if ($PSBoundParameters.ContainsKey('EntryPoint')) { $EntryPoint } else { $current.EntryPoint }
 495    $nextServiceLogPath = if ($ClearServiceLogPath) { $null } elseif ($PSBoundParameters.ContainsKey('ServiceLogPath')) 
 796    $nextPreservePaths = if ($ClearPreservePaths) { @() } elseif ($PSBoundParameters.ContainsKey('PreservePaths')) { @($
 97
 198    if ([string]::IsNullOrWhiteSpace($nextDescription)) {
 199        if ($PSBoundParameters.ContainsKey('Description')) {
 1100            throw 'Parameter -Description cannot be null or empty.'
 101        }
 102
 1103        throw 'Service descriptor is missing a valid Description. Update the descriptor or pass -Description with a non-
 104    }
 105
 1106    if ([string]::IsNullOrWhiteSpace($nextVersion)) {
 1107        if ($PSBoundParameters.ContainsKey('Version')) {
 1108            throw 'Parameter -Version cannot be null or empty and must be compatible with [System.Version].'
 109        }
 110
 1111        throw 'Service descriptor is missing a valid Version. Pass -Version with a value compatible with [System.Version
 112    }
 113
 114    try {
 1115        [void][version]$nextVersion
 116    } catch {
 0117        if ($PSBoundParameters.ContainsKey('Version')) {
 0118            throw 'Parameter -Version cannot be null or empty and must be compatible with [System.Version].'
 119        }
 120
 0121        throw 'Service descriptor is missing a valid Version. Pass -Version with a value compatible with [System.Version
 122    }
 123
 1124    if ([string]::IsNullOrWhiteSpace($nextEntryPoint)) {
 0125        if ($PSBoundParameters.ContainsKey('EntryPoint')) {
 0126            throw 'Parameter -EntryPoint cannot be null or empty.'
 127        }
 128
 0129        throw 'Service descriptor is missing a valid EntryPoint. Update the descriptor or pass -EntryPoint with a non-em
 130    }
 131
 1132    if ([System.IO.Path]::IsPathRooted($nextEntryPoint)) {
 0133        throw "EntryPoint must be a relative path under the descriptor directory: $nextEntryPoint"
 134    }
 135
 1136    $descriptorDirectory = [System.IO.Path]::GetDirectoryName($current.Path)
 2137    $entryPointPath = [System.IO.Path]::GetFullPath((Join-Path -Path $descriptorDirectory -ChildPath $nextEntryPoint))
 2138    $descriptorRootWithSeparator = if ($descriptorDirectory.EndsWith([System.IO.Path]::DirectorySeparatorChar)) { $descr
 1139    if (-not $entryPointPath.StartsWith($descriptorRootWithSeparator, [System.StringComparison]::OrdinalIgnoreCase)) {
 0140        throw "EntryPoint must resolve to a file under descriptor path: $nextEntryPoint"
 141    }
 142
 2143    if (-not (Test-Path -LiteralPath $entryPointPath -PathType Leaf)) {
 1144        throw "EntryPoint file not found under descriptor path: $nextEntryPoint"
 145    }
 146
 1147    $escapedName = $current.Name.Replace("'", "''")
 1148    $escapedDescription = $nextDescription.Replace("'", "''")
 1149    $escapedVersion = $nextVersion.Replace("'", "''")
 150
 1151    $contentLines = [System.Collections.Generic.List[string]]::new()
 1152    $contentLines.Add('@{')
 1153    $contentLines.Add("    FormatVersion = '1.0'")
 1154    $contentLines.Add("    Name = '$escapedName'")
 1155    $contentLines.Add("    Description = '$escapedDescription'")
 1156    $contentLines.Add("    Version = '$escapedVersion'")
 157
 1158    $escapedEntryPoint = $nextEntryPoint.Replace("'", "''")
 1159    $contentLines.Add("    EntryPoint = '$escapedEntryPoint'")
 160
 1161    if (-not [string]::IsNullOrWhiteSpace($nextServiceLogPath)) {
 1162        $escapedServiceLogPath = $nextServiceLogPath.Replace("'", "''")
 1163        $contentLines.Add("    ServiceLogPath = '$escapedServiceLogPath'")
 164    }
 165
 1166    if ($null -ne $nextPreservePaths -and $nextPreservePaths.Count -gt 0) {
 1167        $contentLines.Add('    PreservePaths = @(')
 1168        foreach ($preservePath in $nextPreservePaths) {
 1169            if ([string]::IsNullOrWhiteSpace($preservePath)) {
 170                continue
 171            }
 172
 1173            $escapedPreservePath = $preservePath.Replace("'", "''")
 1174            $contentLines.Add("        '$escapedPreservePath'")
 175        }
 176
 1177        $contentLines.Add('    )')
 178    }
 179
 1180    $contentLines.Add('}')
 181
 1182    if ($PSCmdlet.ShouldProcess($current.Path, 'Update Service.psd1 descriptor (Name is immutable)')) {
 2183        Set-Content -LiteralPath $current.Path -Value ($contentLines -join [Environment]::NewLine) -Encoding utf8NoBOM
 184    }
 185
 1186    Get-KrServiceDescriptor -Path $current.Path
 187}

Methods/Properties

Set-KrServiceDescriptor()