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

refactor(core): ensure_all_installed() to Confirm-InstallationStatus() #3293

Merged
merged 2 commits into from
Apr 29, 2019
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
41 changes: 28 additions & 13 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -438,24 +438,39 @@ function ensure_architecture($architecture_opt) {
}
}

function ensure_all_installed($apps, $global) {
$installed = @()
$apps | Select-Object -Unique | Where-Object { $_.name -ne 'scoop' } | ForEach-Object {
$app, $null, $null = parse_app $_
if(installed $app $false) {
$installed += ,@($app, $false)
} elseif (installed $app $true) {
if($global) {
$installed += ,@($app, $true)
function Confirm-InstallationStatus {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[String[]]
$Apps,
[Switch]
$Global
)
$Installed = @()
$Apps | Select-Object -Unique | Where-Object { $_.Name -ne 'scoop' } | ForEach-Object {
$App, $null, $null = parse_app $_
if ($Global) {
if (installed $App $true) {
$Installed += ,@($App, $true)
} elseif (installed $App $false) {
error "'$App' isn't installed globally, but it is installed for your account."
warn "Try again without the --global (or -g) flag instead."
} else {
error "'$app' isn't installed for your account, but it is installed globally."
warn "Try again with the --global (or -g) flag instead."
error "'$App' isn't installed."
}
} else {
error "'$app' isn't installed."
if(installed $App $false) {
$Installed += ,@($App, $false)
} elseif (installed $App $true) {
error "'$App' isn't installed for your account, but it is installed globally."
warn "Try again with the --global (or -g) flag instead."
} else {
error "'$App' isn't installed."
}
}
}
return ,$installed
return ,$Installed
}

function strip_path($orig_path, $dir) {
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-cleanup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if ($apps) {
$apps += applist (installed_apps $true) $true
}
} else {
$apps = ensure_all_installed $apps $global
$apps = Confirm-InstallationStatus $apps -Global:$global
}

# $apps is now a list of ($app, $global) tuples
Expand Down
4 changes: 2 additions & 2 deletions libexec/scoop-uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if ($apps -eq 'scoop') {
exit
}

$apps = ensure_all_installed $apps $global
$apps = Confirm-InstallationStatus $apps -Global:$global
if (!$apps) { exit 0 }

:app_loop foreach ($_ in $apps) {
Expand Down Expand Up @@ -108,7 +108,7 @@ if (!$apps) { exit 0 }
}
}

if (@(versions $app).length -eq 0) {
if (@(versions $app $global).length -eq 0) {
$appdir = appdir $app $global
try {
# if last install failed, the directory seems to be locked and this
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ if(!$apps) {
$apps += applist (installed_apps $true) $true
}
} else {
$apps = ensure_all_installed $apps_param $global
$apps = Confirm-InstallationStatus $apps_param -Global:$global
}
if($apps) {
$apps | ForEach-Object {
Expand Down