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(scoop-import): Use foreach instead of ForEach-Object for nullity check #5034

Merged
merged 7 commits into from
Jul 7, 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
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
}
}