Skip to content

Commit b4e0ff1

Browse files
zStruCatrashil2000
andauthored
fix(scoop-import): Use foreach instead of ForEach-Object for nullity 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 <46838874+rashil2000@users.noreply.github.com> Co-authored-by: Rashil Gandhi <rashil2000@gmail.com> Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com>
1 parent c5702dd commit b4e0ff1

3 files changed

Lines changed: 18 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- **chore:** Add missing -a/--all param to all commands ([#5004](https://github.com/ScoopInstaller/Scoop/issues/5004))
66
- **scoop-status:** Check bucket status, improve output ([#5011](https://github.com/ScoopInstaller/Scoop/issues/5011))
77
- **scoop-info:** Show app installed/download size ([#4886](https://github.com/ScoopInstaller/Scoop/issues/4886))
8-
- **scoop-import:** Import a Scoop installation from JSON ([#5014](https://github.com/ScoopInstaller/Scoop/issues/5014))
8+
- **scoop-import:** Import a Scoop installation from JSON ([#5014](https://github.com/ScoopInstaller/Scoop/issues/5014), [#5034](https://github.com/ScoopInstaller/Scoop/issues/5034))
99

1010
### Bug Fixes
1111

lib/buckets.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function add_bucket($name, $repo) {
120120

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

libexec/scoop-import.ps1

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Usage: scoop import <path/url to scoopfile.json>
22
# Summary: Imports apps, buckets and configs from a Scoopfile in JSON format
3+
# Help: To replicate a Scoop installation from a file stored on Desktop, run
4+
# scoop import Desktop\scoopfile.json
35

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

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

24-
$import.config.PSObject.Properties | ForEach-Object {
25-
set_config $_.Name $_.Value | Out-Null
26-
Write-Host "'$($_.Name)' has been set to '$($_.Value)'"
26+
foreach ($item in $import.config.PSObject.Properties) {
27+
set_config $item.Name $item.Value | Out-Null
28+
Write-Host "'$($item.Name)' has been set to '$($item.Value)'"
2729
}
2830

29-
$import.buckets | ForEach-Object {
30-
add_bucket $_.Name $_.Source | Out-Null
31-
$bucket_names += $_.Name
31+
foreach ($item in $import.buckets) {
32+
add_bucket $item.Name $item.Source | Out-Null
33+
$bucket_names += $item.Name
3234
}
3335

34-
$import.apps | ForEach-Object {
35-
$info = $_.Info -Split ', '
36+
foreach ($item in $import.apps) {
37+
$info = $item.Info -Split ', '
3638
$global = if ('Global install' -in $info) {
3739
' --global'
3840
} else {
@@ -46,17 +48,17 @@ $import.apps | ForEach-Object {
4648
''
4749
}
4850

49-
$app = if ($_.Source -in $bucket_names) {
50-
"$($_.Source)/$($_.Name)"
51-
} elseif ($_.Source -eq '<auto-generated>') {
52-
"$($_.Name)@$($_.Version)"
51+
$app = if ($item.Source -in $bucket_names) {
52+
"$($item.Source)/$($item.Name)"
53+
} elseif ($item.Source -eq '<auto-generated>') {
54+
"$($item.Name)@$($item.Version)"
5355
} else {
54-
$_.Source
56+
$item.Source
5557
}
5658

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

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

0 commit comments

Comments
 (0)