Skip to content

Commit 5109ffa

Browse files
hlsitechioclaude
andcommitted
feat: interactive package manager selection with choco validation
- Validate choco actually works (not just exists) before using it - If no working package manager found, prompt user to choose: [1] winget (recommended), [2] Chocolatey (install it), [3] Skip - Show both managers when both are available - Link to Microsoft Store for winget if missing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5a251fa commit 5109ffa

1 file changed

Lines changed: 66 additions & 15 deletions

File tree

install.ps1

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,76 @@ function Test-Command($cmd) {
8383
catch { return $false }
8484
}
8585

86+
function Test-ChocoWorks {
87+
try {
88+
$null = & choco --version 2>&1
89+
return ($LASTEXITCODE -eq 0)
90+
} catch {
91+
return $false
92+
}
93+
}
94+
8695
$hasWinget = Test-Command "winget"
87-
$hasChoco = Test-Command "choco"
96+
$hasChoco = (Test-Command "choco") -and (Test-ChocoWorks)
8897

98+
# Report what we found
99+
$pkgMgrFound = $false
89100
if ($hasWinget) {
90-
Write-Ok "winget detected (primary package manager)"
91-
} elseif ($hasChoco) {
92-
Write-Ok "Chocolatey detected (package manager)"
93-
} else {
94-
Write-Warn "No package manager found (winget or Chocolatey)"
95-
Write-Step "Installing Chocolatey..."
96-
try {
97-
Set-ExecutionPolicy Bypass -Scope Process -Force
98-
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
99-
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
100-
$hasChoco = $true
101-
Write-Ok "Chocolatey installed"
102-
} catch {
103-
Write-Err "Could not install Chocolatey: $_"
101+
Write-Ok "winget detected"
102+
$pkgMgrFound = $true
103+
}
104+
if ($hasChoco) {
105+
Write-Ok "Chocolatey detected"
106+
$pkgMgrFound = $true
107+
}
108+
109+
if (-not $pkgMgrFound) {
110+
Write-Warn "No working package manager found"
111+
Write-Host ""
112+
Write-Host " A package manager is needed to install dependencies." -ForegroundColor White
113+
Write-Host " Choose one:" -ForegroundColor White
114+
Write-Host ""
115+
Write-Host " [1] winget (recommended, built into Windows 10/11)" -ForegroundColor Cyan
116+
Write-Host " [2] Chocolatey (community package manager)" -ForegroundColor Cyan
117+
Write-Host " [3] Skip (I'll install dependencies manually)" -ForegroundColor DarkGray
118+
Write-Host ""
119+
$choice = Read-Host " Enter choice (1/2/3)"
120+
121+
switch ($choice) {
122+
"1" {
123+
Write-Step "Checking for winget..."
124+
# winget is built into modern Windows — if missing, point to MS Store
125+
if (Test-Command "winget") {
126+
$hasWinget = $true
127+
Write-Ok "winget is available"
128+
} else {
129+
Write-Warn "winget not found. Install 'App Installer' from the Microsoft Store:"
130+
Write-Host " ms-windows-store://pdp/?productid=9NBLGGH4NNS1" -ForegroundColor Cyan
131+
Write-Host " Then re-run this installer." -ForegroundColor DarkGray
132+
}
133+
}
134+
"2" {
135+
Write-Step "Installing Chocolatey..."
136+
try {
137+
Set-ExecutionPolicy Bypass -Scope Process -Force
138+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
139+
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
140+
$hasChoco = $true
141+
Write-Ok "Chocolatey installed"
142+
} catch {
143+
Write-Err "Could not install Chocolatey: $_"
144+
}
145+
}
146+
default {
147+
Write-Skip "Skipping package manager — dependencies must be installed manually"
148+
}
104149
}
150+
} elseif ($hasWinget -and $hasChoco) {
151+
Write-Ok "Using winget (primary), Chocolatey (fallback)"
152+
} elseif ($hasWinget) {
153+
Write-Ok "Using winget"
154+
} else {
155+
Write-Ok "Using Chocolatey"
105156
}
106157

107158
function Refresh-Path {

0 commit comments

Comments
 (0)