Public/Get-DevVmCurrent.ps1

<#
.SYNOPSIS
Gets the currently active runtime version.
 
.DESCRIPTION
Shows both the version currently in PATH and the configured version from .devvm files.
 
.PARAMETER Runtime
The runtime to check (node, java, maven, etc.)
 
.EXAMPLE
Get-DevVmCurrent -Runtime node
Get-DevVmCurrent -Runtime java
 
#>

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

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

    # Get install path and currently activated version
    $basePath = Get-DevVmInstallPath -Runtime $Runtime
    $activatedVersion = Get-DevVmActivatedVersion -Runtime $Runtime -BasePath $basePath -RuntimeCommand $runtimeInfo.command

    if ($activatedVersion) {
        Write-Output "Active $Runtime in PATH: $activatedVersion"
        try {
            $versionOutput = & $runtimeInfo.command $runtimeInfo.versionFlag 2>&1 | Select-Object -First 1
            Write-Output " Version details: $versionOutput"
        }
        catch {
            Write-Verbose "Failed to read version output for ${Runtime}: $_"
        }
    } else {
        Write-Output "$Runtime is not currently in PATH"
    }

    # Show configured version
    $merged = Get-DevVmMergedConfig -StartPath (Get-Location).Path
    if ($merged.ContainsKey($Runtime)) {
        $configVersion = $merged[$Runtime]
        Write-Output "Configured $Runtime in .devvm: $configVersion"

        if ($activatedVersion -ne $configVersion) {
            Write-Output " (Note: Different from active version - run 'Invoke-DevVmActivate -Runtime $Runtime' to sync)"
        }
    } else {
        Write-Output "No $Runtime version configured in .devvm files"
    }
}