Skip to content

Commit a88d95c

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

3 files changed

Lines changed: 17 additions & 5 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+
Write-Host -ForegroundColor Yellow "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+
Write-Host -ForegroundColor Yellow "No alias found."
9898
}
9999
$aliases = $aliases.GetEnumerator() | Sort-Object Name
100100
if ($verbose) {

libexec/scoop-cache.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ function cacheshow($app) {
2828

2929
$files | ForEach-Object { cacheinfo $_ } | Select-Object Name, Version, Length, URL
3030

31-
Write-Host "Total: $($files.Length) $(pluralize $files.Length 'file' 'files'), $(filesize $totalLength)" -ForegroundColor Yellow
31+
if (!$files.Length) {
32+
Write-Host -ForegroundColor Yellow "No cache found."
33+
} else {
34+
Write-Host "Total: $($files.Length) $(pluralize $files.Length 'file' 'files'), $(filesize $totalLength)" -ForegroundColor Yellow
35+
}
3236
}
3337

3438
function cacheremove($app) {

0 commit comments

Comments
 (0)