| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Retrieves the Kestrun module version information. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function returns the version information of the Kestrun PowerShell module. |
| | | 6 | | It can return either a formatted version string or a detailed object containing version components. |
| | | 7 | | .PARAMETER AsString |
| | | 8 | | If specified, the function returns the version as a formatted string (e.g., "1.2.3-preview"). |
| | | 9 | | If not specified, the function returns a custom object with detailed version information. |
| | | 10 | | .EXAMPLE |
| | | 11 | | Get-KrVersion -AsString |
| | | 12 | | Returns the Kestrun module version as a formatted string. |
| | | 13 | | .EXAMPLE |
| | | 14 | | Get-KrVersion |
| | | 15 | | Returns a custom object with detailed version information. |
| | | 16 | | .NOTES |
| | | 17 | | This function is useful for retrieving version information for logging, diagnostics, or display purposes. |
| | | 18 | | #> |
| | | 19 | | function Get-KrVersion { |
| | | 20 | | [KestrunRuntimeApi('Everywhere')] |
| | | 21 | | [CmdletBinding()] |
| | | 22 | | [OutputType([string])] |
| | | 23 | | [OutputType([psobject])] |
| | | 24 | | param( |
| | | 25 | | [Parameter()] |
| | | 26 | | [switch] $AsString |
| | | 27 | | ) |
| | | 28 | | |
| | 0 | 29 | | $module = Get-Module -Name Kestrun -ErrorAction SilentlyContinue |
| | | 30 | | |
| | 0 | 31 | | if (-not $module) { |
| | 0 | 32 | | Write-Verbose 'Kestrun module is not loaded.' |
| | 0 | 33 | | return $null |
| | | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | $version = $module.Version |
| | 0 | 37 | | $prerelease = $module.PrivateData?.PSData?.Prerelease |
| | | 38 | | |
| | 0 | 39 | | $full = if ($prerelease) { |
| | 0 | 40 | | "$version-$prerelease" |
| | | 41 | | } else { |
| | 0 | 42 | | "$version" |
| | | 43 | | } |
| | | 44 | | |
| | 0 | 45 | | if ($AsString) { |
| | 0 | 46 | | return $full |
| | | 47 | | } |
| | | 48 | | |
| | 0 | 49 | | [pscustomobject]@{ |
| | 0 | 50 | | Name = $module.Name |
| | 0 | 51 | | Version = $version |
| | 0 | 52 | | Prerelease = $prerelease |
| | 0 | 53 | | FullVersion = $full |
| | 0 | 54 | | Path = $module.Path |
| | | 55 | | } |
| | | 56 | | } |