Skip to content

Commit e7c0faa

Browse files
author
L. Yeung
authored
feat(scoop-hold,scoop-unhold): Support -g/--global flag (#4991)
* feat(scoop-hold,scoop-unhold): Support `-g`/`--global` flag * Update CHANGELOG.md
1 parent 9e6c758 commit e7c0faa

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/issues/4956))
66
- **scoop-virustotal:** Migrate to virustotal api v3, improve flows, and ouput powershell objects ([#4983](https://github.com/ScoopInstaller/Scoop/pull/4983))
7+
- **scoop-hold,scoop-unhold:** Support `-g`/`--global` flag ([#4991](https://github.com/ScoopInstaller/Scoop/issues/4991))
78

89
### Bug Fixes
910

libexec/scoop-hold.ps1

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
# Usage: scoop hold <apps>
22
# Summary: Hold an app to disable updates
3+
# Help: To hold a user-scoped app:
4+
# scoop hold <app>
5+
#
6+
# To hold a global app:
7+
# scoop hold -g <app>
8+
#
9+
# Options:
10+
# -g, --global Hold globally installed apps
311

12+
. "$PSScriptRoot\..\lib\getopt.ps1"
413
. "$PSScriptRoot\..\lib\json.ps1" # 'save_install_info' (indirectly)
514
. "$PSScriptRoot\..\lib\manifest.ps1" # 'install_info' 'Select-CurrentVersion' (indirectly)
615
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
716

8-
$apps = $args
17+
$opt, $apps, $err = getopt $args 'g' 'global'
18+
if ($err) { "scoop hold: $err"; exit 1 }
919

10-
if(!$apps) {
20+
$global = $opt.g -or $opt.global
21+
22+
if (!$apps) {
1123
my_usage
1224
exit 1
1325
}
1426

27+
if ($global -and !(is_admin)) {
28+
error 'You need admin rights to hold a global app.'
29+
exit 1
30+
}
31+
1532
$apps | ForEach-Object {
1633
$app = $_
17-
$global = installed $app $true
1834

19-
if (!(installed $app)) {
20-
error "'$app' is not installed."
35+
if (!(installed $app $global)) {
36+
if ($global) {
37+
error "'$app' is not installed globally."
38+
} else {
39+
error "'$app' is not installed."
40+
}
2141
return
2242
}
2343

@@ -29,7 +49,7 @@ $apps | ForEach-Object {
2949
$dir = versiondir $app $version $global
3050
$json = install_info $app $version $global
3151
$install = @{}
32-
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name))}
52+
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name)) }
3353
$install.hold = $true
3454
save_install_info $install $dir
3555
success "$app is now held and can not be updated anymore."

libexec/scoop-unhold.ps1

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
# Usage: scoop unhold <app>
22
# Summary: Unhold an app to enable updates
3+
# Help: To unhold a user-scoped app:
4+
# scoop unhold <app>
5+
#
6+
# To unhold a global app:
7+
# scoop unhold -g <app>
8+
#
9+
# Options:
10+
# -g, --global Unhold globally installed apps
311

12+
. "$PSScriptRoot\..\lib\getopt.ps1"
413
. "$PSScriptRoot\..\lib\json.ps1" # 'save_install_info' (indirectly)
514
. "$PSScriptRoot\..\lib\manifest.ps1" # 'install_info' 'Select-CurrentVersion' (indirectly)
615
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
716

8-
$apps = $args
17+
$opt, $apps, $err = getopt $args 'g' 'global'
18+
if ($err) { "scoop unhold: $err"; exit 1 }
919

10-
if(!$apps) {
20+
$global = $opt.g -or $opt.global
21+
22+
if (!$apps) {
1123
my_usage
1224
exit 1
1325
}
1426

27+
if ($global -and !(is_admin)) {
28+
error 'You need admin rights to unhold a global app.'
29+
exit 1
30+
}
31+
1532
$apps | ForEach-Object {
1633
$app = $_
17-
$global = installed $app $true
1834

19-
if (!(installed $app)) {
20-
error "'$app' is not installed."
35+
if (!(installed $app $global)) {
36+
if ($global) {
37+
error "'$app' is not installed globally."
38+
} else {
39+
error "'$app' is not installed."
40+
}
2141
return
2242
}
2343

@@ -29,7 +49,7 @@ $apps | ForEach-Object {
2949
$dir = versiondir $app $version $global
3050
$json = install_info $app $version $global
3151
$install = @{}
32-
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name))}
52+
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name)) }
3353
$install.hold = $null
3454
save_install_info $install $dir
3555
success "$app is no longer held and can be updated again."

0 commit comments

Comments
 (0)