Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions cli/scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,34 @@ if ($Version -notmatch '^v\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$') {
Write-Host "Installing SynthOrg CLI $Version..."

# --- Detect architecture ---
# Primary: .NET RuntimeInformation (PowerShell 5.1+ with .NET 4.7.1+).
# Fallback: PROCESSOR_ARCHITECTURE env var (always available on Windows).
# The RuntimeInformation API can return $null on older .NET runtimes or
# certain system configurations (see #521).

$OsArch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
$WinArch = switch ($OsArch) {
([System.Runtime.InteropServices.Architecture]::X64) { "amd64" }
([System.Runtime.InteropServices.Architecture]::Arm64) { "arm64" }
default { Write-Error "Unsupported architecture: $OsArch"; exit 1 }
$OsArch = $null
try {
$OsArch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
} catch {
# Type not available - fall through to env var detection.
Write-Verbose "RuntimeInformation unavailable; using PROCESSOR_ARCHITECTURE fallback."
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if ($null -ne $OsArch) {
$WinArch = switch ($OsArch) {
([System.Runtime.InteropServices.Architecture]::X64) { "amd64" }
([System.Runtime.InteropServices.Architecture]::Arm64) { "arm64" }
default { Write-Error "Unsupported architecture: $OsArch"; exit 1 }
}
} else {
# PROCESSOR_ARCHITEW6432 is set when running 32-bit PowerShell on 64-bit
# Windows (WOW64). It contains the real OS architecture.
$ArchEnv = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }
$WinArch = switch ($ArchEnv) {
"AMD64" { "amd64" }
"ARM64" { "arm64" }
default { Write-Error "Unsupported architecture: $ArchEnv"; exit 1 }
}
}
Comment on lines +38 to 61
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the logic is correct, the architecture detection can be simplified to reduce code duplication. You can determine the architecture source first (either from .NET RuntimeInformation or the environment variable), normalize the resulting string, and then use a single, simpler switch statement to determine the $WinArch. This makes the code more concise and easier to maintain.

$DetectedArchStr = $null
try {
    $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
    if ($null -ne $arch) {
        $DetectedArchStr = $arch.ToString()
    }
} catch {
    # Type not available, fall through to env var.
}

if (-not $DetectedArchStr) {
    $DetectedArchStr = $env:PROCESSOR_ARCHITECTURE
}

# Normalize architecture string (e.g. "X64" -> "AMD64")
$NormalizedArch = $DetectedArchStr.ToUpper() -replace "X64", "AMD64"

$WinArch = switch ($NormalizedArch) {
    "AMD64" { "amd64" }
    "ARM64" { "arm64" }
    default { Write-Error "Unsupported architecture: $DetectedArchStr"; exit 1 }
}


# --- Download ---
Expand Down
Loading