Skip to content

Commit

Permalink
Merge commit 'c51ac0a3d13e6d0953b1f78b7778fb99d479d260'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed Jun 19, 2021
2 parents b50699e + c51ac0a commit 6c16bcd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 51 deletions.
50 changes: 23 additions & 27 deletions libexec/scoop-uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,37 @@

Reset-Alias

$opt, $apps, $err = getopt $args 'gp' 'global', 'purge'
if ($err) { Stop-ScoopExecution -Message "scoop uninstall: $err" -ExitCode 2 }
$ExitCode = 0
$Problems = 0
$Options, $Applications, $_err = getopt $args 'gp' 'global', 'purge'

$global = $opt.g -or $opt.global
$purge = $opt.p -or $opt.purge
if ($_err) { Stop-ScoopExecution -Message "scoop uninstall: $_err" -ExitCode 2 }

if (!$apps) { Stop-ScoopExecution -Message 'Parameter <APP> missing' -Usage (my_usage) }
$Global = $Options.g -or $Options.global
$Purge = $Options.p -or $Options.purge

if ($global -and !(is_admin)) {
Stop-ScoopExecution -Message 'Administrator privileges are required to uninstall globally installed applications.' -ExitCode 4
}
if (!$Applications) { Stop-ScoopExecution -Message 'Parameter <APP> missing' -Usage (my_usage) }
if ($Global -and !(is_admin)) { Stop-ScoopExecution -Message 'Administrator privileges are required to uninstall globally installed applications.' -ExitCode 4 }

if ($apps -eq 'scoop') {
& (Join-Path $PSScriptRoot '..\bin\uninstall.ps1') $global $purge
if ($Applications -eq 'scoop') {
& (Join-Path $PSScriptRoot '..\bin\uninstall.ps1') $Global $Purge
exit $LASTEXITCODE
}

$apps = Confirm-InstallationStatus $apps -Global:$global
if (!$apps) {
# This is not strict error
# Keeping it with zero exit code will allow chaining of commands in such use case (mainly vscode tasks dependencies)
Stop-ScoopExecution -Message 'No application to uninstall' -ExitCode 0 -SkipSeverity
}

$exitCode = 0
$problems = 0
$Applications = Confirm-InstallationStatus $Applications -Global:$Global

foreach ($_ in $apps) {
($app, $global, $bucket) = $_
# This is not strict error
# Keeping it with zero exit code will allow chaining of commands in such use case (mainly vscode tasks dependencies)
if (!$Applications) { Stop-ScoopExecution -Message 'No application to uninstall' -ExitCode 0 -SkipSeverity }

foreach ($explode in $Applications) {
($app, $gl, $bucket) = $explode
$result = $false

try {
$result = Uninstall-ScoopApplication -App $app -Global:$global -Purge:$purge -Older
$result = Uninstall-ScoopApplication -App $app -Global:$gl -Purge:$Purge -Older
} catch {
++$problems
++$Problems

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Expand All @@ -59,13 +55,13 @@ foreach ($_ in $apps) {
}

if ($result -eq $false) {
++$problems
++$Problems
continue
}

Write-UserMessage -Message "'$app' was uninstalled." -Success
Write-UserMessage -Message "'$app' was uninstalled" -Success
}

if ($problems -gt 0) { $exitCode = 10 + $problems }
if ($Problems -gt 0) { $ExitCode = 10 + $Problems }

exit $exitCode
exit $ExitCode
51 changes: 27 additions & 24 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,41 @@

Reset-Alias

$opt, $apps, $err = getopt $args 'gfiksq' 'global', 'force', 'independent', 'no-cache', 'skip', 'quiet'
if ($err) { Stop-ScoopExecution -Message "scoop update: $err" -ExitCode 2 }
$ExitCode = 0
$Problems = 0
$Options, $Applications, $_err = getopt $args 'gfiksq' 'global', 'force', 'independent', 'no-cache', 'skip', 'quiet'

if ($_err) { Stop-ScoopExecution -Message "scoop update: $_err" -ExitCode 2 }

# Flags/Parameters
$global = $opt.g -or $opt.global
$force = $opt.f -or $opt.force
$checkHash = !($opt.s -or $opt.skip)
$useCache = !($opt.k -or $opt.'no-cache')
$quiet = $opt.q -or $opt.quiet
$independent = $opt.i -or $opt.independent

$exitCode = 0
if (!$apps) {
if ($global) { Stop-ScoopExecution -Message 'scoop update: --global option is invalid when <APP> is not specified.' -ExitCode 2 }
if (!$useCache) { Stop-ScoopExecution -Message 'scoop update: --no-cache option is invalid when <APP> is not specified.' -ExitCode 2 }
$Global = $Options.g -or $Options.global
$Force = $Options.f -or $Options.force
$CheckHash = !($Options.s -or $Options.skip)
$UseCache = !($Options.k -or $Options.'no-cache')
$Quiet = $Options.q -or $Options.quiet
$Independent = $Options.i -or $Options.independent

if (!$Applications) {
if ($Global) { Stop-ScoopExecution -Message 'scoop update: --global option is invalid when <APP> is not specified.' -ExitCode 2 }
if (!$UseCache) { Stop-ScoopExecution -Message 'scoop update: --no-cache option is invalid when <APP> is not specified.' -ExitCode 2 }

Update-Scoop
} else {
if ($global -and !(is_admin)) { Stop-ScoopExecution -Message 'Admin privileges are required to manipulate with globally installed applications' -ExitCode 4 }
if ($Global -and !(is_admin)) { Stop-ScoopExecution -Message 'Admin privileges are required to manipulate with globally installed applications' -ExitCode 4 }
if (is_scoop_outdated) { Update-Scoop }

$outdatedApplications = @()
$applicationsParam = $apps
$applicationsParam = $Applications # Original users request

if ($applicationsParam -eq '*') {
$apps = applist (installed_apps $false) $false
if ($global) { $apps += applist (installed_apps $true) $true }
$Applications = applist (installed_apps $false) $false
if ($Global) { $Applications += applist (installed_apps $true) $true }
} else {
$apps = Confirm-InstallationStatus $applicationsParam -Global:$global
$Applications = Confirm-InstallationStatus $applicationsParam -Global:$Global
}

if ($apps) {
foreach ($_ in $apps) {
if ($Applications) {
foreach ($_ in $Applications) {
($app, $global, $bb) = $_
$status = app_status $app $global
$bb = $status.bucket
Expand Down Expand Up @@ -80,9 +83,9 @@ if (!$apps) {

foreach ($out in $outdatedApplications) {
try {
Update-App -App $out[0] -Global:$out[1] -Suggested @{ } -Quiet:$quiet -Independent:$independent -SkipCache:(!$useCache) -SkipHashCheck:(!$checkHash)
Update-App -App $out[0] -Global:$out[1] -Suggested @{ } -Quiet:$Quiet -Independent:$Independent -SkipCache:(!$UseCache) -SkipHashCheck:(!$CheckHash)
} catch {
++$problems
++$Problems

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Expand All @@ -95,6 +98,6 @@ if (!$apps) {
}
}

if ($problems -gt 0) { $exitCode = 10 + $problems }
if ($Problems -gt 0) { $ExitCode = 10 + $Problems }

exit $exitCode
exit $ExitCode

0 comments on commit 6c16bcd

Please sign in to comment.