Skip to content

Commit 954caf3

Browse files
author
L. Yeung
committed
fix(bucket): Return empty list correctly in Get-LocalBucket
1 parent e6d0371 commit 954caf3

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

lib/buckets.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ function Get-LocalBucket {
5858
.SYNOPSIS
5959
List all local buckets.
6060
#>
61-
62-
return (Get-ChildItem -Directory $bucketsdir).Name
61+
$bucketNames = (Get-ChildItem -Directory $bucketsdir).Name
62+
if (!$bucketNames.Length) {
63+
return @() # Return a zero-length list instead of $null.
64+
}
65+
return $bucketNames
6366
}
6467

6568
function buckets {
@@ -123,7 +126,12 @@ function Convert-RepositoryUri {
123126

124127
function list_buckets {
125128
$buckets = @()
126-
Get-LocalBucket | ForEach-Object {
129+
$bucketNames = Get-LocalBucket
130+
if (!$bucketNames.Length){
131+
warn "No bucket found. Please run 'scoop bucket add main' to add the default 'main' bucket."
132+
return
133+
}
134+
$bucketNames | ForEach-Object {
127135
$bucket = [Ordered]@{ Name = $_ }
128136
$path = Find-BucketDirectory $_ -Root
129137
if ((Test-Path (Join-Path $path '.git')) -and (Get-Command git -ErrorAction SilentlyContinue)) {

libexec/scoop-alias.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function list_aliases {
9494
}
9595

9696
if (!$aliases.count) {
97-
warn 'No aliases founds.'
97+
info "No alias found."
9898
}
9999
$aliases = $aliases.GetEnumerator() | Sort-Object Name
100100
if ($verbose) {

libexec/scoop-cache.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ function cacheshow($app) {
2424
$app = '(' + ($app -join '|') + ')'
2525
}
2626
$files = @(Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match)
27-
$totalLength = ($files | Measure-Object -Property Length -Sum).Sum
2827

29-
$files | ForEach-Object { cacheinfo $_ } | Select-Object Name, Version, Length, URL
28+
if (!$files.Length) {
29+
$totalLength = 0
30+
} else {
31+
$totalLength = ($files | Measure-Object -Property Length -Sum).Sum
32+
$files | ForEach-Object { cacheinfo $_ } | Select-Object Name, Version, Length, URL
33+
}
3034

3135
Write-Host "Total: $($files.Length) $(pluralize $files.Length 'file' 'files'), $(filesize $totalLength)" -ForegroundColor Yellow
3236
}

0 commit comments

Comments
 (0)