Skip to content

Commit

Permalink
fix(scoop-import): Use foreach instead of ForEach-Object for null…
Browse files Browse the repository at this point in the history
…ity check (#5034)

* Add nullity check and alread_in_local_bucket check

* update CHANGELOG

* Use foreach instead of ForEach-Object

* changelog

* update help

* refine the info and warning when adding an already-added bucket

* Update lib/buckets.ps1

Make warning clearer

Co-authored-by: Rashil Gandhi <[email protected]>

Co-authored-by: Rashil Gandhi <[email protected]>
Co-authored-by: Rashil Gandhi <[email protected]>
  • Loading branch information
3 people authored Jul 7, 2022
1 parent c5702dd commit b4e0ff1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- **chore:** Add missing -a/--all param to all commands ([#5004](https://github.com/ScoopInstaller/Scoop/issues/5004))
- **scoop-status:** Check bucket status, improve output ([#5011](https://github.com/ScoopInstaller/Scoop/issues/5011))
- **scoop-info:** Show app installed/download size ([#4886](https://github.com/ScoopInstaller/Scoop/issues/4886))
- **scoop-import:** Import a Scoop installation from JSON ([#5014](https://github.com/ScoopInstaller/Scoop/issues/5014))
- **scoop-import:** Import a Scoop installation from JSON ([#5014](https://github.com/ScoopInstaller/Scoop/issues/5014), [#5034](https://github.com/ScoopInstaller/Scoop/issues/5034))

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/buckets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function add_bucket($name, $repo) {

$dir = Find-BucketDirectory $name -Root
if (Test-Path $dir) {
warn "The '$name' bucket already exists. Use 'scoop bucket rm $name' to remove it."
warn "The '$name' bucket already exists. To add this bucket again, first remove it by running 'scoop bucket rm $name'."
return 2
}

Expand Down
30 changes: 16 additions & 14 deletions libexec/scoop-import.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Usage: scoop import <path/url to scoopfile.json>
# Summary: Imports apps, buckets and configs from a Scoopfile in JSON format
# Help: To replicate a Scoop installation from a file stored on Desktop, run
# scoop import Desktop\scoopfile.json

param(
[Parameter(Mandatory)]
Expand All @@ -21,18 +23,18 @@ if (Test-Path $scoopfile) {

if (!$import) { abort 'Input file not a valid JSON.' }

$import.config.PSObject.Properties | ForEach-Object {
set_config $_.Name $_.Value | Out-Null
Write-Host "'$($_.Name)' has been set to '$($_.Value)'"
foreach ($item in $import.config.PSObject.Properties) {
set_config $item.Name $item.Value | Out-Null
Write-Host "'$($item.Name)' has been set to '$($item.Value)'"
}

$import.buckets | ForEach-Object {
add_bucket $_.Name $_.Source | Out-Null
$bucket_names += $_.Name
foreach ($item in $import.buckets) {
add_bucket $item.Name $item.Source | Out-Null
$bucket_names += $item.Name
}

$import.apps | ForEach-Object {
$info = $_.Info -Split ', '
foreach ($item in $import.apps) {
$info = $item.Info -Split ', '
$global = if ('Global install' -in $info) {
' --global'
} else {
Expand All @@ -46,17 +48,17 @@ $import.apps | ForEach-Object {
''
}

$app = if ($_.Source -in $bucket_names) {
"$($_.Source)/$($_.Name)"
} elseif ($_.Source -eq '<auto-generated>') {
"$($_.Name)@$($_.Version)"
$app = if ($item.Source -in $bucket_names) {
"$($item.Source)/$($item.Name)"
} elseif ($item.Source -eq '<auto-generated>') {
"$($item.Name)@$($item.Version)"
} else {
$_.Source
$item.Source
}

& "$PSScriptRoot\scoop-install.ps1" $app$global$arch

if ('Held package' -in $info) {
& "$PSScriptRoot\scoop-hold.ps1" $($_.Name)$global
& "$PSScriptRoot\scoop-hold.ps1" $($item.Name)$global
}
}

0 comments on commit b4e0ff1

Please sign in to comment.