From 666d474ee10d6777e0a39c2e998b746f8868dfda Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Mon, 20 Jun 2022 14:43:28 +0800 Subject: [PATCH 01/10] feat(scoop-update): Support `scoop update scoop` (#4992) --- CHANGELOG.md | 1 + lib/core.ps1 | 2 +- libexec/scoop-update.ps1 | 13 +++++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e87db0b67..43a4a76b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/issues/4956)) +- **scoop-update:** Support `scoop update scoop` ([#4992](https://github.com/ScoopInstaller/Scoop/issues/4992)) - **scoop-virustotal:** Migrate to virustotal api v3, improve flows, and ouput powershell objects ([#4983](https://github.com/ScoopInstaller/Scoop/pull/4983)) - **scoop-hold,scoop-unhold:** Support `-g`/`--global` flag ([#4991](https://github.com/ScoopInstaller/Scoop/issues/4991)) diff --git a/lib/core.ps1 b/lib/core.ps1 index 9315f4918e..0a947fa0c4 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -855,7 +855,7 @@ function Confirm-InstallationStatus { $Global ) $Installed = @() - $Apps | Select-Object -Unique | Where-Object { $_.Name -ne 'scoop' } | ForEach-Object { + $Apps | Select-Object -Unique | Where-Object { $_ -ne 'scoop' } | ForEach-Object { $App, $null, $null = parse_app $_ if ($Global) { if (Test-Path (appdir $App $true)) { diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index d06bc5d669..844127f82f 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -306,19 +306,24 @@ if (-not ($apps -or $all)) { 'ERROR: You need admin rights to update global apps.'; exit 1 } - if (is_scoop_outdated) { - update_scoop - } $outdated = @() + $updateScoop = $null -ne ($apps | Where-Object { $_ -eq 'scoop' }) -or (is_scoop_outdated) + $apps = $apps | Where-Object { $_ -ne 'scoop' } $apps_param = $apps + if ($updateScoop) { + update_scoop + } + if ($apps_param -eq '*' -or $all) { $apps = applist (installed_apps $false) $false if ($global) { $apps += applist (installed_apps $true) $true } } else { - $apps = Confirm-InstallationStatus $apps_param -Global:$global + if ($apps_param) { + $apps = Confirm-InstallationStatus $apps_param -Global:$global + } } if ($apps) { $apps | ForEach-Object { From 5987e499b9e6de472584f02fce5a6879e32cdd11 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Tue, 21 Jun 2022 00:13:33 +0800 Subject: [PATCH 02/10] docs(changelog): Update CHANGELOG for v0.2.2 (#5000) A celebratable 5000 --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43a4a76b4b..df6f77ce19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,11 @@ -## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/master...develop) +## [v0.2.2](https://github.com/ScoopInstaller/Scoop/compare/v0.2.1...v0.2.2) - 2022-06-21 ### Features - **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/issues/4956)) +- **scoop-(un)hold:** Add `-g`/`--global` flag ([#4991](https://github.com/ScoopInstaller/Scoop/issues/4991)) - **scoop-update:** Support `scoop update scoop` ([#4992](https://github.com/ScoopInstaller/Scoop/issues/4992)) -- **scoop-virustotal:** Migrate to virustotal api v3, improve flows, and ouput powershell objects ([#4983](https://github.com/ScoopInstaller/Scoop/pull/4983)) -- **scoop-hold,scoop-unhold:** Support `-g`/`--global` flag ([#4991](https://github.com/ScoopInstaller/Scoop/issues/4991)) +- **scoop-virustotal:** Migrate to VirusTotal API v3 ([#4983](https://github.com/ScoopInstaller/Scoop/issues/4983)) ### Bug Fixes From 86e3efbaf0815d7d5cc8b4519670109731926208 Mon Sep 17 00:00:00 2001 From: Ying Fan Chong Date: Tue, 21 Jun 2022 14:12:08 +0800 Subject: [PATCH 03/10] fix(shortcuts): Fix network drive shortcut creation (#4410) Co-authored-by: Rashil Gandhi Co-authored-by: Hsiao-nan Cheung --- CHANGELOG.md | 6 ++++++ lib/shortcuts.ps1 | 22 +++++----------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df6f77ce19..84ced0ebb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/master...develop) + +### Bug Fixes + +- **shortcuts:** Fix network drive shortcut creation ([#4410](https://github.com/ScoopInstaller/Scoop/issues/4410)) + ## [v0.2.2](https://github.com/ScoopInstaller/Scoop/compare/v0.2.1...v0.2.2) - 2022-06-21 ### Features diff --git a/lib/shortcuts.ps1 b/lib/shortcuts.ps1 index 819a4ebd3c..16b658aa51 100644 --- a/lib/shortcuts.ps1 +++ b/lib/shortcuts.ps1 @@ -20,11 +20,12 @@ function create_startmenu_shortcuts($manifest, $dir, $global, $arch) { } function shortcut_folder($global) { - $directory = [System.IO.Path]::Combine([Environment]::GetFolderPath('startmenu'), 'Programs', 'Scoop Apps') - if($global) { - $directory = [System.IO.Path]::Combine([Environment]::GetFolderPath('commonstartmenu'), 'Programs', 'Scoop Apps') + if ($global) { + $startmenu = 'CommonStartMenu' + } else { + $startmenu = 'StartMenu' } - return $(ensure $directory) + return Convert-Path $(ensure [System.IO.Path]::Combine([Environment]::GetFolderPath($startmenu), 'Programs', 'Scoop Apps')) } function startmenu_shortcut([System.IO.FileInfo] $target, $shortcutName, $arguments, [System.IO.FileInfo]$icon, $global) { @@ -67,18 +68,5 @@ function rm_startmenu_shortcuts($manifest, $global, $arch) { if(Test-Path -Path $shortcut) { Remove-Item $shortcut } - # Before issue 1514 Startmenu shortcut removal - # - # Shortcuts that should have been installed globally would - # have been installed locally up until 27 June 2017. - # - # TODO: Remove this 'if' block and comment after - # 27 June 2018. - if($global) { - $shortcut = "$(shortcut_folder $false)\$name.lnk" - if(Test-Path -Path $shortcut) { - Remove-Item $shortcut - } - } } } From 847756bd1e441979c121da8b20b67b56bc53814c Mon Sep 17 00:00:00 2001 From: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> Date: Tue, 21 Jun 2022 11:48:58 +0530 Subject: [PATCH 04/10] refactor(scoop-search): Output PSObject, use API token (#4997) * refactor(scoop-search): Output PSObject, use API token * warn about parsing error * Update CHANGELOG.md * Update scoop-search.ps1 * Apply suggestions from code review Co-authored-by: Hsiao-nan Cheung * separate lines Co-authored-by: Hsiao-nan Cheung --- CHANGELOG.md | 4 ++ lib/manifest.ps1 | 8 ++- libexec/scoop-search.ps1 | 102 +++++++++++++++++++++++++-------------- 3 files changed, 75 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84ced0ebb7..8b0572fc75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - **shortcuts:** Fix network drive shortcut creation ([#4410](https://github.com/ScoopInstaller/Scoop/issues/4410)) +### Code Refactoring + +- **scoop-search:** Output PSObject, use API token ([#4997](https://github.com/ScoopInstaller/Scoop/issues/4997)) + ## [v0.2.2](https://github.com/ScoopInstaller/Scoop/compare/v0.2.1...v0.2.2) - 2022-06-21 ### Features diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index ffa76c7504..ebd99f9abe 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -3,8 +3,12 @@ function manifest_path($app, $bucket) { } function parse_json($path) { - if(!(test-path $path)) { return $null } - Get-Content $path -raw -Encoding UTF8 | convertfrom-json -ea stop + if (!(Test-Path $path)) { return $null } + try { + Get-Content $path -Raw -Encoding UTF8 | ConvertFrom-Json -ErrorAction Stop + } catch { + warn "Error parsing manifest at $path." + } } function url_manifest($url) { diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index d878e53309..adef8b1835 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -9,35 +9,43 @@ param($query) . "$PSScriptRoot\..\lib\manifest.ps1" # 'manifest' . "$PSScriptRoot\..\lib\versions.ps1" # 'Get-LatestVersion' +$list = @() + +try { + $query = New-Object Regex $query, 'IgnoreCase' +} catch { + abort "Invalid regular expression: $($_.Exception.InnerException.Message)" +} + +$githubtoken = Get-GitHubToken +$authheader = @{} +if ($githubtoken) { + $authheader = @{'Authorization' = "token $githubtoken"} +} + function bin_match($manifest, $query) { - if(!$manifest.bin) { return $false } - foreach($bin in $manifest.bin) { + if (!$manifest.bin) { return $false } + $bins = foreach ($bin in $manifest.bin) { $exe, $alias, $args = $bin - $fname = split-path $exe -leaf -ea stop + $fname = Split-Path $exe -Leaf -ErrorAction Stop - if((strip_ext $fname) -match $query) { return $fname } - if($alias -match $query) { return $alias } + if ((strip_ext $fname) -match $query) { $fname } + elseif ($alias -match $query) { $alias } } - $false + if ($bins) { return $bins } + else { return $false } } function search_bucket($bucket, $query) { - $apps = apps_in_bucket (Find-BucketDirectory $bucket) | ForEach-Object { - @{ name = $_ } - } - - if($query) { - try { - $query = new-object regex $query, 'IgnoreCase' - } catch { - abort "Invalid regular expression: $($_.exception.innerexception.message)" - } + $apps = apps_in_bucket (Find-BucketDirectory $bucket) | ForEach-Object { @{ name = $_ } } + if ($query) { $apps = $apps | Where-Object { - if($_.name -match $query) { return $true } + if ($_.name -match $query) { return $true } $bin = bin_match (manifest $_.name $bucket) $query - if($bin) { - $_.bin = $bin; return $true; + if ($bin) { + $_.bin = $bin + return $true } } } @@ -46,14 +54,19 @@ function search_bucket($bucket, $query) { function download_json($url) { $ProgressPreference = 'SilentlyContinue' - $result = Invoke-WebRequest $url -UseBasicParsing | Select-Object -ExpandProperty content | ConvertFrom-Json + $result = Invoke-WebRequest $url -UseBasicParsing -Headers $authheader | Select-Object -ExpandProperty content | ConvertFrom-Json $ProgressPreference = 'Continue' $result } function github_ratelimit_reached { $api_link = 'https://api.github.com/rate_limit' - (download_json $api_link).rate.remaining -eq 0 + $ret = (download_json $api_link).rate.remaining -eq 0 + if ($ret) { + Write-Host "GitHub API rate limit reached. +Please try again later or configure your API token using 'scoop config gh_token '." + } + $ret } function search_remote($bucket, $query) { @@ -72,44 +85,59 @@ function search_remote($bucket, $query) { function search_remotes($query) { $buckets = known_bucket_repos - $names = $buckets | get-member -m noteproperty | Select-Object -exp name + $names = $buckets | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty name - $results = $names | Where-Object { !(test-path $(Find-BucketDirectory $_)) } | ForEach-Object { - @{"bucket" = $_; "results" = (search_remote $_ $query)} + $results = $names | Where-Object { !(Test-Path $(Find-BucketDirectory $_)) } | ForEach-Object { + @{ "bucket" = $_; "results" = (search_remote $_ $query) } } | Where-Object { $_.results } if ($results.count -gt 0) { - "Results from other known buckets..." - "(add them using 'scoop bucket add ')" - "" + Write-Host "Results from other known buckets... +(add them using 'scoop bucket add ')" } $results | ForEach-Object { - "'$($_.bucket)' bucket (install using 'scoop install $($_.bucket)/'):" - $_.results | ForEach-Object { " $_" } - "" + $name = $_.bucket + $_.results | ForEach-Object { + $item = [ordered]@{} + $item.Name = $_ + $item.Source = $name + $list += [PSCustomObject]$item + } } + + $list } Get-LocalBucket | ForEach-Object { $res = search_bucket $_ $query $local_results = $local_results -or $res - if($res) { + if ($res) { $name = "$_" - Write-Host "'$name' bucket:" $res | ForEach-Object { - $item = " $($_.name) ($($_.version))" - if($_.bin) { $item += " --> includes '$($_.bin)'" } - $item + $item = [ordered]@{} + $item.Name = $_.name + $item.Version = $_.version + $item.Source = $name + $item.Binaries = "" + if ($_.bin) { $item.Binaries = $_.bin -join ' | ' } + $list += [PSCustomObject]$item } - "" } } +if ($list.Length -gt 0) { + Write-Host "Results from local buckets..." + $list +} + if (!$local_results -and !(github_ratelimit_reached)) { $remote_results = search_remotes $query - if(!$remote_results) { [console]::error.writeline("No matches found."); exit 1 } + if (!$remote_results) { + warn "No matches found." + exit 1 + } $remote_results } From 9723725402a2a0392cb093ae1bcf81b982df85e9 Mon Sep 17 00:00:00 2001 From: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> Date: Tue, 21 Jun 2022 12:08:05 +0530 Subject: [PATCH 05/10] fix(chore): Update help documentation (#5002) * tweaks to help system * update help text * update changelog * fix order of printing deps * Apply suggestions from code review Co-authored-by: Hsiao-nan Cheung * Update scoop-help.ps1 * Update scoop.ps1 Co-authored-by: Hsiao-nan Cheung --- CHANGELOG.md | 1 + bin/scoop.ps1 | 2 +- libexec/scoop-alias.ps1 | 8 ++++---- libexec/scoop-depends.ps1 | 11 +++++++---- libexec/scoop-download.ps1 | 4 ++++ libexec/scoop-help.ps1 | 29 +++++++++++++++-------------- libexec/scoop-install.ps1 | 4 ++++ 7 files changed, 36 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b0572fc75..d742ef65e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Bug Fixes +- **chore:** Update help documentation ([#5002](https://github.com/ScoopInstaller/Scoop/issues/5002)) - **shortcuts:** Fix network drive shortcut creation ([#4410](https://github.com/ScoopInstaller/Scoop/issues/4410)) ### Code Refactoring diff --git a/bin/scoop.ps1 b/bin/scoop.ps1 index b7a29c1c53..6d96c68b2f 100644 --- a/bin/scoop.ps1 +++ b/bin/scoop.ps1 @@ -47,7 +47,7 @@ switch ($subCommand) { } } default { - "scoop: '$subCommand' isn't a scoop command. See 'scoop help'." + warn "scoop: '$subCommand' isn't a scoop command. See 'scoop help'." exit 1 } } diff --git a/libexec/scoop-alias.ps1 b/libexec/scoop-alias.ps1 index e226548d50..d60884c351 100644 --- a/libexec/scoop-alias.ps1 +++ b/libexec/scoop-alias.ps1 @@ -52,10 +52,10 @@ function add_alias($name, $command) { # generate script $shimdir = shimdir $false $script = - @" -# Summary: $description -$command -"@ + @( + "# Summary: $description", + "$command" + ) -join "`r`n" $script | Out-UTF8File "$shimdir\$alias_file.ps1" # add alias to config diff --git a/libexec/scoop-depends.ps1 b/libexec/scoop-depends.ps1 index e6b501b468..33d2558089 100644 --- a/libexec/scoop-depends.ps1 +++ b/libexec/scoop-depends.ps1 @@ -1,5 +1,5 @@ # Usage: scoop depends -# Summary: List dependencies for an app +# Summary: List dependencies for an app, in the order they'll be installed . "$PSScriptRoot\..\lib\getopt.ps1" . "$PSScriptRoot\..\lib\depends.ps1" # 'Get-Dependency' @@ -17,9 +17,12 @@ try { abort "ERROR: $_" } -$deps = @(Get-Dependency $app $architecture) -ne $app -if($deps) { - $deps[($deps.length - 1)..0] +$deps = @() +Get-Dependency $app $architecture | ForEach-Object { + $dep = [ordered]@{} + $dep.Source, $dep.Name = $_ -split '/' + $deps += [PSCustomObject]$dep } +$deps exit 0 diff --git a/libexec/scoop-download.ps1 b/libexec/scoop-download.ps1 index 846750eb97..05ba2fa052 100644 --- a/libexec/scoop-download.ps1 +++ b/libexec/scoop-download.ps1 @@ -3,6 +3,10 @@ # Help: e.g. The usual way to download an app, without installing it (uses your local 'buckets'): # scoop download git # +# To download a different version of the app +# (note that this will auto-generate the manifest using current version): +# scoop download gh@2.7.0 +# # To download an app from a manifest at a URL: # scoop download https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/runat.json # diff --git a/libexec/scoop-help.ps1 b/libexec/scoop-help.ps1 index 819800ece0..54ed8a9319 100644 --- a/libexec/scoop-help.ps1 +++ b/libexec/scoop-help.ps1 @@ -3,41 +3,42 @@ param($cmd) function print_help($cmd) { - $file = Get-Content (command_path $cmd) -raw + $file = Get-Content (command_path $cmd) -Raw $usage = usage $file - $summary = summary $file $help = scoop_help $file - if($usage) { "$usage`n" } - if($help) { $help } + if ($usage) { "$usage`n" } + if ($help) { $help } } function print_summaries { - $commands = @{} + $commands = @() command_files | ForEach-Object { - $command = command_name $_ - $summary = summary (Get-Content (command_path $command) -raw) - if(!($summary)) { $summary = '' } - $commands.add("$command ", $summary) # add padding + $command = [ordered]@{} + $command.Command = command_name $_ + $command.Summary = summary (Get-Content (command_path $command.Command)) + $commands += [PSCustomObject]$command } - $commands.getenumerator() | Sort-Object name | Format-Table -hidetablehead -autosize -wrap + $commands } $commands = commands if(!($cmd)) { - "Usage: scoop [] + Write-Host "Usage: scoop [] -Some useful commands are:" +Available commands are listed below. + +Type 'scoop help ' to get more help for a specific command." print_summaries - "Type 'scoop help ' to get help for a specific command." } elseif($commands -contains $cmd) { print_help $cmd } else { - "scoop help: no such command '$cmd'"; exit 1 + warn "scoop help: no such command '$cmd'" + exit 1 } exit 0 diff --git a/libexec/scoop-install.ps1 b/libexec/scoop-install.ps1 index a0c856a502..4865ea2848 100644 --- a/libexec/scoop-install.ps1 +++ b/libexec/scoop-install.ps1 @@ -3,6 +3,10 @@ # Help: e.g. The usual way to install an app (uses your local 'buckets'): # scoop install git # +# To install a different version of the app +# (note that this will auto-generate the manifest using current version): +# scoop install gh@2.7.0 +# # To install an app from a manifest at a URL: # scoop install https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/runat.json # From 0fd66575720cc19bc9b3cd985e9afee6c8c875ba Mon Sep 17 00:00:00 2001 From: Francois Botha Date: Tue, 21 Jun 2022 08:46:35 +0200 Subject: [PATCH 06/10] tests(typo): Fix typo ('formated' -> 'formatted') (#4217) Co-authored-by: Hsiao-nan Cheung --- CHANGELOG.md | 4 ++++ test/Import-File-Tests.ps1 | 2 +- test/Scoop-Depends.Tests.ps1 | 2 +- test/Scoop-Format-Manifest.Tests.ps1 | 6 +++--- test/fixtures/format/{formated => formatted}/1-easy.json | 0 .../format/{formated => formatted}/2-whitespaces-mess.json | 0 .../3-array-with-single-and-multi.json | 0 .../format/{formated => formatted}/4-script-block.json | 0 .../fixtures/format/{unformated => unformatted}/1-easy.json | 0 .../{unformated => unformatted}/2-whitespaces-mess.json | 0 .../3-array-with-single-and-multi.json | 0 .../format/{unformated => unformatted}/4-script-block.json | 0 12 files changed, 9 insertions(+), 5 deletions(-) rename test/fixtures/format/{formated => formatted}/1-easy.json (100%) rename test/fixtures/format/{formated => formatted}/2-whitespaces-mess.json (100%) rename test/fixtures/format/{formated => formatted}/3-array-with-single-and-multi.json (100%) rename test/fixtures/format/{formated => formatted}/4-script-block.json (100%) rename test/fixtures/format/{unformated => unformatted}/1-easy.json (100%) rename test/fixtures/format/{unformated => unformatted}/2-whitespaces-mess.json (100%) rename test/fixtures/format/{unformated => unformatted}/3-array-with-single-and-multi.json (100%) rename test/fixtures/format/{unformated => unformatted}/4-script-block.json (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index d742ef65e0..5f90d6ebc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ - **scoop-search:** Output PSObject, use API token ([#4997](https://github.com/ScoopInstaller/Scoop/issues/4997)) +### Tests + +- **typo:** Fix typo ('formated' -> 'formatted') ([#4217](https://github.com/ScoopInstaller/Scoop/issues/4217)) + ## [v0.2.2](https://github.com/ScoopInstaller/Scoop/compare/v0.2.1...v0.2.2) - 2022-06-21 ### Features diff --git a/test/Import-File-Tests.ps1 b/test/Import-File-Tests.ps1 index a1ae343f10..0359e8069f 100644 --- a/test/Import-File-Tests.ps1 +++ b/test/Import-File-Tests.ps1 @@ -10,7 +10,7 @@ Describe 'Style constraints for non-binary project files' { $repo_files | Where-Object { $_.fullname -inotmatch $($project_file_exclusions -join '|') } | Where-Object { $_.fullname -inotmatch '(.exe|.zip|.dll)$' } | - Where-Object { $_.fullname -inotmatch '(unformated)' } + Where-Object { $_.fullname -inotmatch '(unformatted)' } ) $files_exist = ($files.Count -gt 0) diff --git a/test/Scoop-Depends.Tests.ps1 b/test/Scoop-Depends.Tests.ps1 index 4a58db2443..03713c0c3e 100644 --- a/test/Scoop-Depends.Tests.ps1 +++ b/test/Scoop-Depends.Tests.ps1 @@ -32,7 +32,7 @@ Describe 'Package Dependencies' -Tag 'Scoop' { Context 'InstallationHelper function' { BeforeAll { - $working_dir = setup_working 'format/formated' + $working_dir = setup_working 'format/formatted' $manifest1 = parse_json (Join-Path $working_dir '3-array-with-single-and-multi.json') $manifest2 = parse_json (Join-Path $working_dir '4-script-block.json') Mock Test-HelperInstalled { $false } diff --git a/test/Scoop-Format-Manifest.Tests.ps1 b/test/Scoop-Format-Manifest.Tests.ps1 index e74f782bd0..25bc9730ce 100644 --- a/test/Scoop-Format-Manifest.Tests.ps1 +++ b/test/Scoop-Format-Manifest.Tests.ps1 @@ -5,7 +5,7 @@ Describe 'Pretty json formating' -Tag 'Scoop' { BeforeAll { $format = "$PSScriptRoot\fixtures\format" - $manifests = Get-ChildItem "$format\formated" -File -Filter '*.json' + $manifests = Get-ChildItem "$format\formatted" -File -Filter '*.json' } Context 'Beautify manifest' { @@ -13,8 +13,8 @@ Describe 'Pretty json formating' -Tag 'Scoop' { if ($PSVersionTable.PSVersion.Major -gt 5) { $_ = $_.Name } # Fix for pwsh It "$_" { - $pretty_json = (parse_json "$format\unformated\$_") | ConvertToPrettyJson - $correct = (Get-Content "$format\formated\$_") -join "`r`n" + $pretty_json = (parse_json "$format\unformatted\$_") | ConvertToPrettyJson + $correct = (Get-Content "$format\formatted\$_") -join "`r`n" $correct.CompareTo($pretty_json) | Should -Be 0 } } diff --git a/test/fixtures/format/formated/1-easy.json b/test/fixtures/format/formatted/1-easy.json similarity index 100% rename from test/fixtures/format/formated/1-easy.json rename to test/fixtures/format/formatted/1-easy.json diff --git a/test/fixtures/format/formated/2-whitespaces-mess.json b/test/fixtures/format/formatted/2-whitespaces-mess.json similarity index 100% rename from test/fixtures/format/formated/2-whitespaces-mess.json rename to test/fixtures/format/formatted/2-whitespaces-mess.json diff --git a/test/fixtures/format/formated/3-array-with-single-and-multi.json b/test/fixtures/format/formatted/3-array-with-single-and-multi.json similarity index 100% rename from test/fixtures/format/formated/3-array-with-single-and-multi.json rename to test/fixtures/format/formatted/3-array-with-single-and-multi.json diff --git a/test/fixtures/format/formated/4-script-block.json b/test/fixtures/format/formatted/4-script-block.json similarity index 100% rename from test/fixtures/format/formated/4-script-block.json rename to test/fixtures/format/formatted/4-script-block.json diff --git a/test/fixtures/format/unformated/1-easy.json b/test/fixtures/format/unformatted/1-easy.json similarity index 100% rename from test/fixtures/format/unformated/1-easy.json rename to test/fixtures/format/unformatted/1-easy.json diff --git a/test/fixtures/format/unformated/2-whitespaces-mess.json b/test/fixtures/format/unformatted/2-whitespaces-mess.json similarity index 100% rename from test/fixtures/format/unformated/2-whitespaces-mess.json rename to test/fixtures/format/unformatted/2-whitespaces-mess.json diff --git a/test/fixtures/format/unformated/3-array-with-single-and-multi.json b/test/fixtures/format/unformatted/3-array-with-single-and-multi.json similarity index 100% rename from test/fixtures/format/unformated/3-array-with-single-and-multi.json rename to test/fixtures/format/unformatted/3-array-with-single-and-multi.json diff --git a/test/fixtures/format/unformated/4-script-block.json b/test/fixtures/format/unformatted/4-script-block.json similarity index 100% rename from test/fixtures/format/unformated/4-script-block.json rename to test/fixtures/format/unformatted/4-script-block.json From 83d0fef02fbba226f4e78214cba2f5254688334d Mon Sep 17 00:00:00 2001 From: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> Date: Tue, 21 Jun 2022 18:31:20 +0530 Subject: [PATCH 07/10] fix(shortcuts): Fix missing parentheses (#5006) * fix(shortcuts): Fix missing parentheses * Update CHANGELOG.md --- CHANGELOG.md | 2 +- lib/shortcuts.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f90d6ebc2..57d04b51dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### Bug Fixes - **chore:** Update help documentation ([#5002](https://github.com/ScoopInstaller/Scoop/issues/5002)) -- **shortcuts:** Fix network drive shortcut creation ([#4410](https://github.com/ScoopInstaller/Scoop/issues/4410)) +- **shortcuts:** Fix network drive shortcut creation ([#4410](https://github.com/ScoopInstaller/Scoop/issues/4410)), ([#5006](https://github.com/ScoopInstaller/Scoop/issues/5006)) ### Code Refactoring diff --git a/lib/shortcuts.ps1 b/lib/shortcuts.ps1 index 16b658aa51..e8ddec26bb 100644 --- a/lib/shortcuts.ps1 +++ b/lib/shortcuts.ps1 @@ -25,7 +25,7 @@ function shortcut_folder($global) { } else { $startmenu = 'StartMenu' } - return Convert-Path $(ensure [System.IO.Path]::Combine([Environment]::GetFolderPath($startmenu), 'Programs', 'Scoop Apps')) + return Convert-Path (ensure ([System.IO.Path]::Combine([Environment]::GetFolderPath($startmenu), 'Programs', 'Scoop Apps'))) } function startmenu_shortcut([System.IO.FileInfo] $target, $shortcutName, $arguments, [System.IO.FileInfo]$icon, $global) { From 4fec4d70894dd8b9d80a20e830d663dffeb7b374 Mon Sep 17 00:00:00 2001 From: tech189 Date: Tue, 21 Jun 2022 16:22:01 +0100 Subject: [PATCH 08/10] feat(scoop-info): Show app installed/download size (#4886) Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> Co-authored-by: Hsiao-nan Cheung --- CHANGELOG.md | 4 +++ libexec/scoop-info.ps1 | 79 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57d04b51dd..51b296ecd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/master...develop) +### Features + +- **scoop-info:** Show app installed/download size ([#4886](https://github.com/ScoopInstaller/Scoop/issues/4886)) + ### Bug Fixes - **chore:** Update help documentation ([#5002](https://github.com/ScoopInstaller/Scoop/issues/5002)) diff --git a/libexec/scoop-info.ps1 b/libexec/scoop-info.ps1 index d4e186136e..74f7aa931a 100644 --- a/libexec/scoop-info.ps1 +++ b/libexec/scoop-info.ps1 @@ -105,6 +105,85 @@ if ($status.installed) { $installed_output += if ($verbose) { versiondir $app $_ $global } else { "$_$(if ($global) { " *global*" })" } } $item.Installed = $installed_output -join "`n" + + if ($verbose) { + # Show size of installation + $appsdir = appsdir $global + + # Collect file list from each location + $appFiles = Get-ChildItem $appsdir -Filter $app + $currentFiles = Get-ChildItem $appFiles -Filter (Select-CurrentVersion $app $global) + $persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data + $cacheFiles = Get-ChildItem $cachedir -Filter "$app#*" + + # Get the sum of each file list + $fileTotals = @() + foreach ($fileType in ($appFiles, $currentFiles, $persistFiles, $cacheFiles)) { + if ($null -ne $fileType) { + $fileSum = (Get-ChildItem $fileType -Recurse | Measure-Object -Property Length -Sum).Sum + $fileTotals += coalesce $fileSum 0 + } else { + $fileTotals += 0 + } + } + + # Old versions = app total - current version size + $fileTotals += $fileTotals[0] - $fileTotals[1] + + if ($fileTotals[2] + $fileTotals[3] + $fileTotals[4] -eq 0) { + # Simple app size output if no old versions, persisted data, cached downloads + $item.'Installed size' = filesize $fileTotals[1] + } else { + $fileSizes = [ordered] @{ + 'Current version: ' = $fileTotals[1] + 'Old versions: ' = $fileTotals[4] + 'Persisted data: ' = $fileTotals[2] + 'Cached downloads: ' = $fileTotals[3] + 'Total: ' = $fileTotals[0] + $fileTotals[2] + $fileTotals[3] + } + + $fileSizeOutput = @() + + # Don't output empty categories + $fileSizes.GetEnumerator() | ForEach-Object { + if ($_.Value -ne 0) { + $fileSizeOutput += $_.Key + (filesize $_.Value) + } + } + + $item.'Installed size' = $fileSizeOutput -join "`n" + } + } +} else { + if ($verbose) { + # Get download size if app not installed + $totalPackage = 0 + foreach ($url in @(url $manifest (default_architecture))) { + try { + if (Test-Path (fullpath (cache_path $app $manifest.version $url))) { + $cached = " (latest version is cached)" + } else { + $cached = $null + } + + [int]$urlLength = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length'[0] + $totalPackage += $urlLength + } catch [System.Management.Automation.RuntimeException] { + $totalPackage = 0 + $packageError = "the server at $(([System.Uri]$url).Host) did not send a Content-Length header" + break + } catch { + $totalPackage = 0 + $packageError = "the server at $(([System.Uri]$url).Host) is down" + break + } + } + if ($totalPackage -ne 0) { + $item.'Download size' = "$(filesize $totalPackage)$cached" + } else { + $item.'Download size' = "Unknown ($packageError)$cached" + } + } } $binaries = @(arch_specific 'bin' $manifest $install.architecture) From 6629331799764ab325aa2c6811022cb76334f246 Mon Sep 17 00:00:00 2001 From: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> Date: Wed, 22 Jun 2022 15:40:24 +0530 Subject: [PATCH 09/10] feat(scoop-status): Check bucket status, improve output (#5011) * feat(scoop-status): Check bucket status, improve output * Update CHANGELOG.md --- CHANGELOG.md | 1 + libexec/scoop-status.ps1 | 112 ++++++++------------ supporting/formats/ScoopTypes.Format.ps1xml | 29 +++++ 3 files changed, 75 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51b296ecd8..293e5bb5f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- **scoop-status:** Check bucket status, improve output ([#5011](https://github.com/ScoopInstaller/Scoop/issues/5011)) - **scoop-info:** Show app installed/download size ([#4886](https://github.com/ScoopInstaller/Scoop/issues/4886)) ### Bug Fixes diff --git a/libexec/scoop-status.ps1 b/libexec/scoop-status.ps1 index 878656693c..da2b634f87 100644 --- a/libexec/scoop-status.ps1 +++ b/libexec/scoop-status.ps1 @@ -7,24 +7,40 @@ # check if scoop needs updating $currentdir = fullpath $(versiondir 'scoop' 'current') $needs_update = $false +$bucket_needs_update = $false +$script:network_failure = $false +$list = @() +if (!(Get-FormatData ScoopStatus)) { + Update-FormatData "$PSScriptRoot\..\supporting\formats\ScoopTypes.Format.ps1xml" +} -if (Test-Path "$currentdir\.git") { - git_cmd -C "`"$currentdir`"" fetch -q origin - $commits = $(git -C $currentdir log "HEAD..origin/$(get_config SCOOP_BRANCH)" --oneline) - if ($commits) { $needs_update = $true } -} else { - $needs_update = $true +function Test-UpdateStatus($repopath) { + if (Test-Path "$repopath\.git") { + git_cmd -C "`"$repopath`"" fetch -q origin + $script:network_failure = 128 -eq $LASTEXITCODE + $branch = git -C $repopath branch --show-current + $commits = git -C $repopath log "HEAD..origin/$branch" --oneline + if ($commits) { return $true } + else { return $false } + } else { + return $true + } } -if ($needs_update) { - warn "Scoop is out of date. Run 'scoop update' to get the latest changes." -} else { success 'Scoop is up to date.' } +$needs_update = Test-UpdateStatus $currentdir +foreach ($bucket in Get-LocalBucket) { + if (Test-UpdateStatus (Find-BucketDirectory $bucket -Root)) { + $bucket_needs_update = $true + } +} -$failed = @() -$outdated = @() -$removed = @() -$missing_deps = @() -$onhold = @() +if ($needs_update) { + warn "Scoop out of date. Run 'scoop update' to get the latest changes." +} elseif ($bucket_needs_update) { + warn "Scoop bucket(s) out of date. Run 'scoop update' to get the latest changes." +} elseif (!$script:network_failure) { + success 'Scoop is up to date.' +} $true, $false | ForEach-Object { # local and global apps $global = $_ @@ -34,64 +50,26 @@ $true, $false | ForEach-Object { # local and global apps Get-ChildItem $dir | Where-Object name -NE 'scoop' | ForEach-Object { $app = $_.name $status = app_status $app $global - if ($status.failed) { - $failed += @{ $app = $status.version } - } - if ($status.removed) { - $removed += @{ $app = $status.version } - } - 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)) - } - } -} - -if ($outdated) { - Write-Host -f DarkCyan 'Updates are available for:' - $outdated.keys | ForEach-Object { - $versions = $outdated.$_ - " $_`: $($versions[0]) -> $($versions[1])" - } -} - -if ($onhold) { - Write-Host -f DarkCyan 'These apps are outdated and on hold:' - $onhold.keys | ForEach-Object { - $versions = $onhold.$_ - " $_`: $($versions[0]) -> $($versions[1])" - } -} + if (!$status.outdated -and !$status.failed -and !$status.removed -and !$status.missing_deps) { return } -if ($removed) { - Write-Host -f DarkCyan 'These app manifests have been removed:' - $removed.keys | ForEach-Object { - " $_" + $item = [ordered]@{} + $item.Name = $app + $item.'Installed Version' = $status.version + $item.'Latest Version' = if ($status.outdated) { $status.latest_version } else { "" } + $item.'Missing Dependencies' = $status.missing_deps -Split ' ' -Join ' | ' + $info = $() + if ($status.failed) { $info += 'Install failed' } + if ($status.hold) { $info += 'Held package' } + if ($status.removed) { $info += 'Manifest removed' } + $item.Info = $info -join ', ' + $list += [PSCustomObject]$item } } -if ($failed) { - Write-Host -f DarkCyan 'These apps failed to install:' - $failed.keys | ForEach-Object { - " $_" - } -} - -if ($missing_deps) { - Write-Host -f DarkCyan 'Missing runtime dependencies:' - $missing_deps | ForEach-Object { - $app, $deps = $_ - " '$app' requires '$([string]::join("', '", $deps))'" - } -} - -if (!$old -and !$removed -and !$failed -and !$missing_deps -and !$needs_update) { +if ($list.Length -eq 0 -and !$needs_update -and !$bucket_needs_update -and !$script:network_failure) { success 'Everything is ok!' } +$list | Add-Member -TypeName ScoopStatus -PassThru + exit 0 diff --git a/supporting/formats/ScoopTypes.Format.ps1xml b/supporting/formats/ScoopTypes.Format.ps1xml index b2dff49d84..ba423f9553 100644 --- a/supporting/formats/ScoopTypes.Format.ps1xml +++ b/supporting/formats/ScoopTypes.Format.ps1xml @@ -60,5 +60,34 @@ + + ScoopStatusType + + ScoopStatus + + + + + + + Name + + + Installed Version + + + Latest Version + + + Missing Dependencies + + + Info + + + + + + From 9811a5f8536d01e8faba9b8cb36da333c10a9dc7 Mon Sep 17 00:00:00 2001 From: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com> Date: Wed, 22 Jun 2022 15:47:31 +0530 Subject: [PATCH 10/10] feat(chore): Add missing -a/--all param to all commands (#5004) * feat(scoop-reset): Add -a/--all switch to reset all apps * feat(scoop-cache): Add -a/--all switch to delete whole cache * feat(scoop-virustotal): Add -e/--every switch to check every installed app * Update CHANGELOG.md * use 'all' instead of 'every' --- CHANGELOG.md | 1 + libexec/scoop-cache.ps1 | 4 +++- libexec/scoop-reset.ps1 | 9 ++++++--- libexec/scoop-virustotal.ps1 | 10 +++++----- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 293e5bb5f6..b8f59d4732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- **chore:** Add missing -a/--all param to all commands ([#5004](https://github.com/ScoopInstaller/Scoop/issues/5004)) - **scoop-status:** Check bucket status, improve output ([#5011](https://github.com/ScoopInstaller/Scoop/issues/5011)) - **scoop-info:** Show app installed/download size ([#4886](https://github.com/ScoopInstaller/Scoop/issues/4886)) diff --git a/libexec/scoop-cache.ps1 b/libexec/scoop-cache.ps1 index 96cd23763c..959c73fcde 100644 --- a/libexec/scoop-cache.ps1 +++ b/libexec/scoop-cache.ps1 @@ -10,6 +10,8 @@ # # To clear everything in your cache, use: # scoop cache rm * +# You can also use the `-a/--all` switch in place of `*` here + param($cmd) function cacheinfo($file) { @@ -36,7 +38,7 @@ function cacheremove($app) { 'ERROR: missing' my_usage exit 1 - } elseif ($app -eq '*') { + } elseif ($app -eq '*' -or $app -eq '-a' -or $app -eq '--all') { $files = @(Get-ChildItem $cachedir) } else { $app = '(' + ($app -join '|') + ')' diff --git a/libexec/scoop-reset.ps1 b/libexec/scoop-reset.ps1 index 05cefe47cc..f84328bcbe 100644 --- a/libexec/scoop-reset.ps1 +++ b/libexec/scoop-reset.ps1 @@ -3,6 +3,8 @@ # 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. +# +# You can use '*' in place of or `-a`/`--all` switch to reset all apps. . "$PSScriptRoot\..\lib\getopt.ps1" . "$PSScriptRoot\..\lib\manifest.ps1" # 'Select-CurrentVersion' (indirectly) @@ -10,12 +12,13 @@ . "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion' . "$PSScriptRoot\..\lib\shortcuts.ps1" -$opt, $apps, $err = getopt $args +$opt, $apps, $err = getopt $args 'a' 'all' if($err) { "scoop reset: $err"; exit 1 } +$all = $opt.a -or $opt.all -if(!$apps) { error ' missing'; my_usage; exit 1 } +if(!$apps -and !$all) { error ' missing'; my_usage; exit 1 } -if($apps -eq '*') { +if($apps -eq '*' -or $all) { $local = installed_apps $false | ForEach-Object { ,@($_, $false) } $global = installed_apps $true | ForEach-Object { ,@($_, $true) } $apps = @($local) + @($global) diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index 37da80ce52..ef4b84e2f6 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -2,7 +2,7 @@ # Summary: Look for app's hash or url on virustotal.com # Help: Look for app's hash or url on virustotal.com # -# Use a single '*' for app to check all installed apps. +# Use a single '*' or the '-a/--all' switch to check all installed apps. # # To use this command, you have to sign up to VirusTotal's community, # and get an API key. Then, tell scoop about your API key with: @@ -20,7 +20,7 @@ # 2 & 4 combined # # Options: -# -a, --arch <32bit|64bit> Use the specified architecture, if the app supports it +# -a, --all Check for all installed apps # -s, --scan For packages where VirusTotal has no information, send download URL # for analysis (and future retrieval). This requires you to configure # your virustotal_api_key. @@ -34,10 +34,10 @@ . "$PSScriptRoot\..\lib\install.ps1" # 'hash_for_url' . "$PSScriptRoot\..\lib\depends.ps1" # 'Get-Dependency' -$opt, $apps, $err = getopt $args 'a:snup' @('arch=', 'scan', 'no-depends', 'no-update-scoop', 'passthru') +$opt, $apps, $err = getopt $args 'asnup' @('all', 'scan', 'no-depends', 'no-update-scoop', 'passthru') if ($err) { "scoop virustotal: $err"; exit 1 } if (!$apps) { my_usage; exit 1 } -$architecture = ensure_architecture ($opt.a + $opt.arch) +$architecture = ensure_architecture if (is_scoop_outdated) { if ($opt.u -or $opt.'no-update-scoop') { @@ -49,7 +49,7 @@ if (is_scoop_outdated) { $apps_param = $apps -if ($apps_param -eq '*') { +if ($apps_param -eq '*' -or $opt.a -or $opt.all) { $apps = installed_apps $false $apps += installed_apps $true }