< Summary - Kestrun — Combined Coverage

Information
Class: Public.Helper.Initialize-KrRoot
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Helper/Initialize-KrRoot.ps1
Tag: Kestrun/Kestrun@5f1d2b981c9d7292c11fd448428c6ab6c811c5de
Line coverage
0%
Covered lines: 0
Uncovered lines: 7
Coverable lines: 7
Total lines: 56
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 11/19/2025 - 17:40:50 Line coverage: 0% (0/7) Total lines: 56 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd026

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Helper/Initialize-KrRoot.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Initializes the Kestrun root directory for path resolution.
 4    .DESCRIPTION
 5        This function sets the Kestrun root directory, which is used as a base for resolving relative paths in Kestrun a
 6        It is typically called during the initialization phase of a Kestrun application.
 7        This function should be called before any other Kestrun commands that rely on the root directory being set.
 8    .PARAMETER Path
 9        The path to the Kestrun root directory.
 10    .PARAMETER PassThru
 11        If specified, the cmdlet will return the absolute path to the Kestrun root directory after setting it.
 12    .EXAMPLE
 13        Initialize-KrRoot -Path "C:\Kestrun"
 14        Sets the Kestrun root directory to "C:\Kestrun".
 15    .EXAMPLE
 16        Initialize-KrRoot -Path "~/Kestrun"
 17        Sets the Kestrun root directory to the user's home directory.
 18    .EXAMPLE
 19        Initialize-KrRoot -Path "D:\Projects\Kestrun"
 20        Sets the Kestrun root directory to "D:\Projects\Kestrun".
 21    .EXAMPLE
 22        Initialize-KrRoot -Path "C:\Kestrun" -PassThru
 23        Returns the absolute path to the Kestrun root directory.
 24    .OUTPUTS
 25        [string] The absolute path to the Kestrun root directory.
 26    .NOTES
 27        This function is designed to be used in the context of a Kestrun server to ensure consistent path resolution.
 28#>
 29function Initialize-KrRoot {
 30    [CmdletBinding()]
 31    [KestrunRuntimeApi('Definition')]
 32    [OutputType([string])]
 33    param(
 34        [Parameter(Mandatory, Position = 0)]
 35        [string] $Path,
 36        [switch] $PassThru
 37    )
 38
 39    # Expand ~
 040    if ($Path -like '~*') {
 041        $Path = $Path -replace '^~', $HOME
 42    }
 43
 44    # Resolve to absolute path
 045    $resolvedPath = Resolve-Path -Path $Path -ErrorAction Stop |
 046        Select-Object -First 1 -ExpandProperty Path
 47
 48    # Save for use in C# runtime
 049    [Kestrun.KestrunHostManager]::KestrunRoot = $resolvedPath
 50
 051    if ($PassThru) {
 52        # Return absolute path for chaining
 053        return [Kestrun.KestrunHostManager]::KestrunRoot
 54    }
 55}
 56

Methods/Properties

Initialize-KrRoot()