Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bucket): Return empty list correctly in Get-LocalBucket #4885

Merged
merged 1 commit into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- **update:** Skip logs starting with `(chore)` ([#4800](https://github.com/ScoopInstaller/Scoop/issues/4800))
- **scoop-download:** Add failure check ([#4822](https://github.com/ScoopInstaller/Scoop/pull/4822))
- **install:** Fix issue with installation inside containers ([#4837](https://github.com/ScoopInstaller/Scoop/pull/4837))
- **bucket:** Return empty list correctly in `Get-LocalBucket` ([#4885](https://github.com/ScoopInstaller/Scoop/pull/4885))

### Performance Improvements

Expand Down
8 changes: 6 additions & 2 deletions lib/buckets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ function Get-LocalBucket {
.SYNOPSIS
List all local buckets.
#>

return (Get-ChildItem -Directory $bucketsdir).Name
$bucketNames = (Get-ChildItem -Path $bucketsdir -Directory).Name
if ($null -eq $bucketNames) {
return @() # Return a zero-length list instead of $null.
} else {
return $bucketNames
}
}

function buckets {
Expand Down
3 changes: 3 additions & 0 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ function filesize($length) {
} elseif($length -gt $kb) {
"{0:n1} KB" -f ($length / $kb)
} else {
if ($null -eq $length) {
$length = 0
}
"$($length) B"
}
}
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-alias.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function list_aliases {
}

if (!$aliases.count) {
warn 'No aliases founds.'
info "No alias found."
}
$aliases = $aliases.GetEnumerator() | Sort-Object Name
if ($verbose) {
Expand Down
10 changes: 8 additions & 2 deletions libexec/scoop-bucket.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ switch ($cmd) {
exit $status
}
'list' {
list_buckets
exit 0
$buckets = list_buckets
if (!$buckets.Length) {
warn "No bucket found. Please run 'scoop bucket add main' to add the default 'main' bucket."
exit 2
} else {
$buckets
exit 0
}
}
'known' {
known_buckets
Expand Down