Functions/Use-EverixControl.ps1

function Use-EverixControl {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true, Position = 0)]
        [string] $version,
        [string] $everixControlLocation = "$HOME/everix-control"
    )

    try {
    
        $everixControlLocation = [IO.Path]::GetFullPath($everixControlLocation)    
        $versions = Get-EverixControlVersions -everixControlLocation $everixControlLocation

        # check if version is in the list
        if ($versions -contains $version) {
            Write-Host "✅ Found everix-control version '$version' in '$everixControlLocation'." -ForegroundColor Green
        } else {
            Write-Error "everix-control version '$version' not found in '$everixControlLocation'."
            Write-Output "Available versions: $($versions -join ', ')"
        
            exit 1
        }

        Write-Host "⌛ Setting everix-control version '$version' in the environment..."
        [Environment]::SetEnvironmentVariable("EVERIX_CONTROL_VERSION", $version, [System.EnvironmentVariableTarget]::User)
        $env:EVERIX_CONTROL_VERSION = $version

        Write-Host "🚀 everix-control version '$version' is now set in the environment: you can use 'Start-EverixControl' (alias 'everix-control')" -ForegroundColor Green
    } catch {
        Write-Error $_.Exception.Message
    }
}