Skip to content

Commit

Permalink
Improve reset command
Browse files Browse the repository at this point in the history
Allow resetting:
* global apps
* multiple apps
* all apps by using * parameter (skips global apps if not admin)
  • Loading branch information
r15ch13 committed Feb 16, 2018
1 parent 8f65c7c commit 7176719
Showing 1 changed file with 54 additions and 24 deletions.
78 changes: 54 additions & 24 deletions libexec/scoop-reset.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,79 @@
# Help: Used to resolve conflicts in favor of a particular app. For example,
# if you've installed 'python' and 'python27', you can use 'scoop reset' to switch between
# using one or the other.
param($app)

. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\manifest.ps1"
. "$psscriptroot\..\lib\help.ps1"
. "$psscriptroot\..\lib\getopt.ps1"
. "$psscriptroot\..\lib\install.ps1"
. "$psscriptroot\..\lib\versions.ps1"
. "$psscriptroot\..\lib\config.ps1"
. "$psscriptroot\..\lib\shortcuts.ps1"

reset_aliases
$opt, $apps, $err = getopt $args
if($err) { "scoop reset: $err"; exit 1 }

if(!$app) { 'ERROR: <app> missing'; my_usage; exit 1 }
if(!$apps) { error 'ERROR: <app> missing'; my_usage; exit 1 }

$appWithVersion = get_app_with_version $app
$app = $appWithVersion.app;
$version = $appWithVersion.version;
if($apps -eq '*') {
$local = installed_apps $false | % { ,@($_, $false) }
$global = installed_apps $true | % { ,@($_, $true) }
$apps = @($local) + @($global)
}

$apps | ForEach-Object {
($app, $global) = $_

if(!(installed $app)) { abort "'$app' isn't installed" }
if(($global -eq $null) -and (installed $app $true)) {
# set global flag when running reset command on specific app
$global = $true
}

if ($version -eq 'latest') {
$version = current_version $app
}
if($app -eq 'scoop') {
# skip scoop
return
}

$manifest = installed_manifest $app $version
# if this is null we know the version they're resetting to
# is not installed
if ($manifest -eq $null) {
abort "'$app ($version)' isn't installed"
}
$appWithVersion = get_app_with_version $app
$app = $appWithVersion.app;
$version = $appWithVersion.version;

if(!(installed $app)) {
error "'$app' isn't installed"
return
}

"Resetting $app ($version)."
if ($version -eq 'latest') {
$version = current_version $app $global
}

$dir = resolve-path (versiondir $app $version)
$manifest = installed_manifest $app $version $global
# if this is null we know the version they're resetting to
# is not installed
if ($manifest -eq $null) {
error "'$app ($version)' isn't installed"
return
}

$install = install_info $app $version
$architecture = $install.architecture
if($global -and !(is_admin)) {
warn "'$app' ($version) is a global app. You need admin rights to reset it. Skipping."
return
}

$dir = link_current $dir
create_shims $manifest $dir $false $architecture
create_startmenu_shortcuts $manifest $dir $false
env_add_path $manifest $dir
env_set $manifest $dir
write-host "Resetting $app ($version)."

$dir = resolve-path (versiondir $app $version $global)

$install = install_info $app $version $global
$architecture = $install.architecture

$dir = link_current $dir
create_shims $manifest $dir $global $architecture
create_startmenu_shortcuts $manifest $dir $global $architecture
env_add_path $manifest $dir
env_set $manifest $dir $global
}

exit 0

0 comments on commit 7176719

Please sign in to comment.