Public/Get-DevVmVersion.ps1

<#
.SYNOPSIS
Lists installed versions of a runtime.
 
.DESCRIPTION
Displays all installed versions of the specified runtime.
Shows which version is selected (from .devvm files) and whether it's activated in PATH.
 
.PARAMETER Runtime
The runtime to list versions for (node, java, maven, etc.)
 
.PARAMETER All
Show detailed information for all versions.
 
.EXAMPLE
Get-DevVmVersion -Runtime node
Get-DevVmVersion -Runtime java -All
 
#>

function Get-DevVmVersion {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateScript({ Test-DevVmRuntime $_ })]
        [string]$Runtime,

        [switch]$All
    )

    $runtimeInfo = Get-DevVmRuntimeInfo -Runtime $Runtime
    if (-not $runtimeInfo) {
        Write-Error "Runtime '$Runtime' not configured"
        return
    }

    $basePath = Get-DevVmInstallPath -Runtime $Runtime

    if (-not (Test-Path $basePath)) {
        Write-Output "No versions installed at: $basePath"
        return
    }

    $versions = @(Get-ChildItem -Path $basePath -Directory -ErrorAction SilentlyContinue)

    if ($versions.Count -eq 0) {
        Write-Output "No versions installed for $Runtime at $basePath"
        return
    }

    # Get merged configuration
    $merged = Get-DevVmMergedConfig -StartPath (Get-Location).Path
    $selectedVersion = $merged[$Runtime]

    # Detect activated version
    $activatedVersion = Get-DevVmActivatedVersion -Runtime $Runtime -BasePath $basePath -RuntimeCommand $runtimeInfo.command

    Write-Output "Versions of $Runtime installed at $basePath (Total: $($versions.Count)):"
    Write-Output ""

    foreach ($version in $versions) {
        $versionName = $version.Name
        $markers = @()

        if ($selectedVersion -and $versionName -eq $selectedVersion) {
            $markers += "selected"
        }

        if ($activatedVersion -and $versionName -eq $activatedVersion) {
            $markers += "activated"
        }

        if ($markers.Count -gt 0) {
            Write-Output " $versionName [$($markers -join ', ')]"
        } else {
            Write-Output " $versionName"
        }

        if ($All) {
            Write-Output " Path: $($version.FullName)"
        }
    }
}