Public/Clear-DevVmPath.ps1

<#
.SYNOPSIS
Removes runtimes from persistent user PATH.
 
.DESCRIPTION
Removes DevVm runtime entries from the user's persistent PATH environment variable.
Can remove a specific runtime or all DevVm runtimes.
 
.PARAMETER Runtime
The runtime to remove from PATH. If not specified, removes all DevVm runtimes.
 
.EXAMPLE
Clear-DevVmPath -Runtime node
 
.EXAMPLE
Clear-DevVmPath
 
.EXAMPLE
devvm path clear node
 
#>

function Clear-DevVmPath {
    [CmdletBinding(SupportsShouldProcess = $true)]
    param(
        [Parameter(Position = 0)]
        [string]$Runtime
    )

    if ($Runtime) {
        # Validate runtime exists
        if (-not (Test-DevVmRuntime -Runtime $Runtime)) {
            Write-Error -Message "Unknown runtime: $Runtime"
            return
        }

        $basePath = Get-DevVmInstallPath -Runtime $Runtime

        if ($PSCmdlet.ShouldProcess($Runtime, "Remove from persistent PATH")) {
            $result = Remove-DevVmPersistentPath -Runtime $Runtime -BasePath $basePath
            if ($result) {
                Write-Output -InputObject "[OK] $Runtime removed from persistent PATH"
                Write-Warning -Message "Restart terminal for changes to apply in new windows."
            }
        }
    }
    else {
        # Remove all DevVm entries
        if ($PSCmdlet.ShouldProcess("All DevVm runtimes", "Remove from persistent PATH")) {
            $removed = 0
            foreach ($rt in $script:DevVmConfig.RuntimeDefinitions.runtimes.PSObject.Properties.Name) {
                $basePath = Get-DevVmInstallPath -Runtime $rt
                $result = Remove-DevVmPersistentPath -Runtime $rt -BasePath $basePath -Confirm:$false
                if ($result) {
                    $removed++
                }
            }

            if ($removed -gt 0) {
                Write-Output -InputObject ""
                Write-Output -InputObject "[OK] Removed $removed runtime(s) from persistent PATH"
                Write-Warning -Message "Restart terminal for changes to apply in new windows."
            }
            else {
                Write-Output -InputObject "No DevVm runtimes found in persistent PATH."
            }
        }
    }
}