Public/Install-DevVmVersion.ps1

<#
.SYNOPSIS
Installs a new version of a runtime.
 
.DESCRIPTION
Downloads and installs a specific version of a runtime.
The version is installed in the configured base path for that runtime.
 
.PARAMETER Runtime
The runtime to install (node, java, maven, etc.)
 
.PARAMETER Version
The version to install.
 
.EXAMPLE
Install-DevVmVersion -Runtime node -Version 20.0.0
Install-DevVmVersion -Runtime java -Version 21.0.1
 
#>

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

        [Parameter(Mandatory = $true)]
        [string]$Version
    )

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

    $basePath = Get-DevVmInstallPath -Runtime $Runtime
    $installPath = Join-Path -Path $basePath -ChildPath $Version

    if (Test-Path $installPath) {
        Write-Output "$Runtime version $Version is already installed at $installPath"
        return
    }

    # Ensure base path exists
    if (-not (Test-Path $basePath)) {
        New-Item -ItemType Directory -Path $basePath -Force | Out-Null
    }

    Write-Output "Installing $Runtime version $Version..."
    Write-Output "Source: $($runtimeInfo.downloadUrl -replace '{version}', $Version)"
    Write-Output "Destination: $installPath"

    # Call private download/extract function
    Invoke-DevVmDownloadAndInstall -Runtime $Runtime -Version $Version -RuntimeInfo $runtimeInfo -InstallPath $installPath
}