Skip to content

Commit a007526

Browse files
committed
get-aspire-cli.ps1: detect archive type by extension (.zip/.tar.gz); remove OS param from Expand-AspireCliArchive; default install path to ~/.aspire
1 parent b82f77a commit a007526

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

eng/scripts/get-aspire-cli.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,7 @@ function Test-FileChecksum {
626626
function Expand-AspireCliArchive {
627627
param(
628628
[string]$ArchiveFile,
629-
[string]$DestinationPath,
630-
[string]$OS
629+
[string]$DestinationPath
631630
)
632631

633632
Write-Message "Unpacking archive to: $DestinationPath" -Level Verbose
@@ -639,16 +638,14 @@ function Expand-AspireCliArchive {
639638
New-Item -ItemType Directory -Path $DestinationPath -Force | Out-Null
640639
}
641640

642-
if ($OS -eq "win") {
643-
# Use Expand-Archive for ZIP files on Windows
641+
if ($ArchiveFile -match "\.zip$") {
644642
if (-not (Get-Command Expand-Archive -ErrorAction SilentlyContinue)) {
645643
throw "Expand-Archive cmdlet not found. Please use PowerShell 5.0 or later to extract ZIP files."
646644
}
647645

648646
Expand-Archive -Path $ArchiveFile -DestinationPath $DestinationPath -Force
649647
}
650-
else {
651-
# Use tar for tar.gz files on Unix systems
648+
elseif ($ArchiveFile -match "\.tar\.gz$") {
652649
if (-not (Get-Command tar -ErrorAction SilentlyContinue)) {
653650
throw "tar command not found. Please install tar to extract tar.gz files."
654651
}
@@ -657,11 +654,17 @@ function Expand-AspireCliArchive {
657654
try {
658655
Set-Location $DestinationPath
659656
& tar -xzf $ArchiveFile
657+
if ($LASTEXITCODE -ne 0) {
658+
throw "Failed to extract tar.gz archive: $ArchiveFile. tar command returned exit code $LASTEXITCODE"
659+
}
660660
}
661661
finally {
662662
Set-Location $currentLocation
663663
}
664664
}
665+
else {
666+
throw "Unsupported archive format: $ArchiveFile. Only .zip and .tar.gz files are supported."
667+
}
665668

666669
Write-Message "Successfully unpacked archive" -Level Verbose
667670
}
@@ -715,7 +718,7 @@ function Get-InstallPath {
715718
throw "Unable to determine user home directory. Please specify -InstallPath parameter."
716719
}
717720

718-
$defaultPath = Join-Path (Join-Path $homeDirectory ".aspire") "bin"
721+
$defaultPath = Join-Path $homeDirectory ".aspire"
719722
return [System.IO.Path]::GetFullPath($defaultPath)
720723
}
721724

@@ -875,7 +878,7 @@ function Install-AspireCli {
875878

876879
if ($PSCmdlet.ShouldProcess($InstallPath, "Install CLI")) {
877880
# Unpack the archive
878-
Expand-AspireCliArchive -ArchiveFile $archivePath -DestinationPath $InstallPath -OS $targetOS
881+
Expand-AspireCliArchive -ArchiveFile $archivePath -DestinationPath $InstallPath
879882

880883
$cliExe = if ($targetOS -eq "win") { "aspire.exe" } else { "aspire" }
881884
$cliPath = Join-Path $InstallPath $cliExe

0 commit comments

Comments
 (0)