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

feat(scoop-cache): Allow multiple apps to be passed #141

Merged
merged 11 commits into from
Apr 24, 2021
Next Next commit
feat(scoop-cache): Allow multiple apps to be passed
- Unify getopt #106
  • Loading branch information
Ash258 committed Apr 14, 2021
commit 50476dab57fb3078bf26cdf465167f55c6ee2cb9
20 changes: 20 additions & 0 deletions lib/Cache.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

function cacheinfo($file) {
$app, $version, $url = $file.name -split '#'
$size = filesize $file.length
return New-Object PSObject -prop @{ 'app' = $app; 'version' = $version; 'url' = $url; 'size' = $size }
}

function show($app) {
$files = @(Get-ChildItem $SCOOP_CACHE_DIRECTORY | Where-Object -Property 'Name' -Match "^$app")
$total_length = ($files | Measure-Object length -Sum).sum -as [double]

$f_app = @{ 'Expression' = { "$($_.app) ($($_.version))" } }
$f_url = @{ 'Expression' = { $_.url }; 'Alignment' = 'Right' }
$f_size = @{ 'Expression' = { $_.size }; 'Alignment' = 'Right' }


$files | ForEach-Object { cacheinfo $_ } | Format-Table $f_size, $f_app, $f_url -AutoSize -HideTableHeaders

"Total: $($files.length) $(pluralize $files.length 'file' 'files'), $(filesize $total_length)"
}
49 changes: 24 additions & 25 deletions libexec/scoop-cache.ps1
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
# Usage: scoop cache [rm|show] [app] [options]
# Summary: Show or clear the download cache
# Help: Scoop caches downloads so you don't need to download the same files
# when you uninstall and re-install the same version of an app.
# Usage: scoop cache [<COMMAND>] [<OPTIONS>] [<APP>...]
# Summary: Show or clear the download cache.
# Help: Scoop caches downloaded files to remove the need for repeated downloads of same files.
#
# You can use
# scoop cache show
# to see what's in the cache, and
# scoop cache rm <app>
# scoop cache rm git
# to remove downloads for a specific app.
#
# To clear everything in your cache, use:
# To clear everything in cache, use:
# scoop cache rm *
#
# Commands:
# rm Remove an application specific files from cache.
# show Show an overview of all cached files.
#
# Options:
# -h, --help Show help for this command.

param($cmd, $app)

. (Join-Path $PSScriptRoot '..\lib\help.ps1')

Reset-Alias

function cacheinfo($file) {
$app, $version, $url = $file.name -split '#'
$size = filesize $file.length
return New-Object PSObject -prop @{ 'app' = $app; 'version' = $version; 'url' = $url; 'size' = $size }
'core', 'Cache', 'getopt', 'help' | ForEach-Object {
. (Join-Path $PSScriptRoot "..\lib\$_.ps1")
}

function show($app) {
$files = @(Get-ChildItem $SCOOP_CACHE_DIRECTORY | Where-Object -Property 'Name' -Match "^$app")
$total_length = ($files | Measure-Object length -Sum).sum -as [double]
Reset-Alias

$f_app = @{ 'Expression' = { "$($_.app) ($($_.version))" } }
$f_url = @{ 'Expression' = { $_.url }; 'Alignment' = 'Right' }
$f_size = @{ 'Expression' = { $_.size }; 'Alignment' = 'Right' }
$opt, $arguments, $err = getopt $args
if ($err) { Stop-ScoopExecution -Message "scoop cache: $err" -ExitCode 2 }

$cmd = if ($arguments[0]) { $arguments[0] } else { 'show' }
$isShow = $cmd -eq 'show'
$applications = $arguments[1..($arguments.Count)]

$files | ForEach-Object { cacheinfo $_ } | Format-Table $f_size, $f_app, $f_url -AutoSize -HideTableHeaders
if ($cmd -notin @('rm', 'show')) { Stop-ScoopExecution -Message "Unknown subcommand: '$cmd'" -Usage (my_usage) }
if (!$isShow -and !$applications) { Stop-ScoopExecution -Message 'Parameter <apps> missing' -Usage (my_usage) }

"Total: $($files.length) $(pluralize $files.length 'file' 'files'), $(filesize $total_length)"
$exitCode = 0
# if ($)
foreach ($app in $applications) {
continue
}
exit 258

$exitCode = 0
switch ($cmd) {
'rm' {
if (!$app) { Stop-ScoopExecution -Message 'Parameter <app> missing' -Usage (my_usage) }
Expand Down