Skip to content

Commit

Permalink
feature(update): Add hold/unhold command (ScoopInstaller#3444)
Browse files Browse the repository at this point in the history
Allows un/locking a program to the current version and enable/disable updates.
Close ScoopInstaller#3232
Close ScoopInstaller#1941
  • Loading branch information
r15ch13 authored May 8, 2019
1 parent 8beffc4 commit 44975dc
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ function app_status($app, $global) {
$install_info = install_info $app $status.version $global

$status.failed = (!$install_info -or !$status.version)
$status.hold = ($install_info.hold -eq $true)

$manifest = manifest $app $install_info.bucket $install_info.url
$status.removed = (!$manifest)
Expand Down
33 changes: 33 additions & 0 deletions libexec/scoop-hold.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Usage: scoop hold <apps>
# Summary: Hold an app to disable updates

. "$psscriptroot\..\lib\help.ps1"
. "$psscriptroot\..\lib\manifest.ps1"

reset_aliases
$apps = $args

if(!$apps) {
my_usage
exit 1
}

$apps | ForEach-Object {
$app = $_
$global = installed $app $true

if (!(installed $app)) {
error "'$app' is not installed."
return
}

$dir = versiondir $app 'current' $global
$json = install_info $app 'current' $global
$install = @{}
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name))}
$install.hold = $true
save_install_info $install $dir
success "$app is now locked and can not be updated anymore."
}

exit $exitcode
1 change: 1 addition & 0 deletions libexec/scoop-list.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if($apps) {
if($global) { write-host -f DarkGreen ' *global*' -NoNewline }

if (!$install_info) { Write-Host ' *failed*' -ForegroundColor DarkRed -NoNewline }
if ($install_info.hold) { Write-Host ' *hold*' -ForegroundColor DarkMagenta -NoNewline }

if ($install_info.bucket -and ($install_info.bucket -ne 'main')) {
write-host -f Yellow " [$($install_info.bucket)]" -NoNewline
Expand Down
12 changes: 12 additions & 0 deletions libexec/scoop-status.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $failed = @()
$outdated = @()
$removed = @()
$missing_deps = @()
$onhold = @()

$true, $false | ForEach-Object { # local and global apps
$global = $_
Expand All @@ -52,6 +53,9 @@ $true, $false | ForEach-Object { # local and global apps
}
if($status.outdated) {
$outdated += @{ $app = @($status.version, $status.latest_version) }
if($status.hold) {
$onhold += @{ $app = @($status.version, $status.latest_version) }
}
}
if($status.missing_deps) {
$missing_deps += ,(@($app) + @($status.missing_deps))
Expand All @@ -67,6 +71,14 @@ if($outdated) {
}
}

if($onhold) {
write-host -f DarkCyan 'These apps are outdated and on hold:'
$onhold.keys | ForEach-Object {
$versions = $onhold.$_
" $_`: $($versions[0]) -> $($versions[1])"
}
}

if($removed) {
write-host -f DarkCyan 'These app manifests have been removed:'
$removed.keys | ForEach-Object {
Expand Down
33 changes: 33 additions & 0 deletions libexec/scoop-unhold.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Usage: scoop unhold <app>
# Summary: Unhold an app to enable updates

. "$psscriptroot\..\lib\help.ps1"
. "$psscriptroot\..\lib\manifest.ps1"

reset_aliases
$apps = $args

if(!$apps) {
my_usage
exit 1
}

$apps | ForEach-Object {
$app = $_
$global = installed $app $true

if (!(installed $app)) {
error "'$app' is not installed."
return
}

$dir = versiondir $app 'current' $global
$json = install_info $app 'current' $global
$install = @{}
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name))}
$install.hold = $null
save_install_info $install $dir
success "$app is now unlocked and can be updated again."
}

exit $exitcode
18 changes: 11 additions & 7 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,21 @@ if (!$apps) {
($app, $global) = $_
$status = app_status $app $global
if ($force -or $status.outdated) {
$outdated += applist $app $global
write-host -f yellow ("$app`: $($status.version) -> $($status.latest_version){0}" -f ('',' (global)')[$global])
if(!$status.hold) {
$outdated += applist $app $global
write-host -f yellow ("$app`: $($status.version) -> $($status.latest_version){0}" -f ('',' (global)')[$global])
} else {
warn "'$app' is locked to version $($status.version)"
}
} elseif ($apps_param -ne '*') {
write-host -f green "$app`: $($status.version) (latest version)"
}
}

if ($outdated -and (Test-Aria2Enabled)) {
warn "Scoop uses 'aria2c' for multi-connection downloads."
warn "Should it cause issues, run 'scoop config aria2-enabled false' to disable it."
}
if ($outdated.Length -gt 1) {
write-host -f DarkCyan "Updating $($outdated.Length) outdated apps:"
} elseif ($outdated.Length -eq 0) {
Expand All @@ -306,11 +314,7 @@ if (!$apps) {
}

$suggested = @{};
# # $outdated is a list of ($app, $global) tuples
if (Test-Aria2Enabled) {
warn "Scoop uses 'aria2c' for multi-connection downloads."
warn "Should it cause issues, run 'scoop config aria2-enabled false' to disable it."
}
# $outdated is a list of ($app, $global) tuples
$outdated | ForEach-Object { update @_ $quiet $independent $suggested $use_cache $check_hash }
}

Expand Down

0 comments on commit 44975dc

Please sign in to comment.