From 45e8c3018f95ab5e64ec0d889f3ef8b600335fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 16 May 2021 13:24:51 -0700 Subject: [PATCH 01/14] feat(scoop-search): Add --api, -a option Use custom API backend for searching --- lib/Search.ps1 | 11 +++++++++++ libexec/scoop-search.ps1 | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/Search.ps1 b/lib/Search.ps1 index 017f7dc056..8f0fbcfdd0 100644 --- a/lib/Search.ps1 +++ b/lib/Search.ps1 @@ -207,3 +207,14 @@ function Search-LocalBucket { end { return $result } } + +function Search-RemoteAPI { + [CmdletBinding()] + param([String] $Query) + + process { + $res = Invoke-RestMethod -Uri "https://api.shovel.ash258.com/api/v1/?query=$Query&size=10000&page=0" + + return $res.content + } +} diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index 362e182edf..7be7060687 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -9,6 +9,9 @@ # -r, --remote Force remote search in known buckets using Github API. # Remote search does not utilize advanced search methods (descriptions, binary, shortcuts, ... matching). # It only uses manifest name to search. +# -a, --api Use shovel.ash258.com API backend for search. +# Regular expression is not supported. +# Currently in experimental phase with limited feature-set. Search is done on manifest names only. 'getopt', 'buckets', 'Helpers', 'Search' | ForEach-Object { . (Join-Path $PSScriptRoot "..\lib\$_.ps1") @@ -16,9 +19,10 @@ Reset-Alias -$opt, $Query, $err = getopt $args 'r' 'remote' +$opt, $Query, $err = getopt $args 'ra' 'remote', 'api' if ($err) { Stop-ScoopExecution -Message "scoop search: $err" -ExitCode 2 } $Remote = $opt.r -or $opt.remote +$Api = $opt.a -or $opt.api if ($Query) { try { $Query = New-Object System.Text.RegularExpressions.Regex $Query, 'IgnoreCase' @@ -68,7 +72,7 @@ foreach ($bucket in (Get-LocalBucket)) { } if (!$localResults) { Write-UserMessage -Message 'No matches in local buckets found' } -if (!$localResults -or $Remote) { +if (!$Api -and (!$localResults -or $Remote)) { if (!(Test-GithubApiRateLimitBreached)) { Write-Host 'Searching in remote buckets ...' $remoteResults = Search-AllRemote -Query $Query @@ -87,4 +91,14 @@ if (!$localResults -or $Remote) { } } +if ($Api) { + $results = Search-RemoteAPI -Query $Query + + # TODO: Bucket url + # TODO: Prompt for bucket addition + $results | ForEach-Object { + Write-Host "$($_.name) ($($_.version)) - URL - remote URL" -f red + } +} + exit $exitCode From aa017b07c24ad28c43ef0399a2b0f08fb73722d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sat, 5 Jun 2021 16:31:38 +0200 Subject: [PATCH 02/14] feat(scoop-download): Adopt Resolve-ManifestInformation (#164) --- lib/install.ps1 | 4 +-- lib/manifest.ps1 | 9 ++++-- libexec/scoop-download.ps1 | 62 ++++++++++++++----------------------- test/Scoop-Config.Tests.ps1 | 24 +++++++------- 4 files changed, 44 insertions(+), 55 deletions(-) diff --git a/lib/install.ps1 b/lib/install.ps1 index 635f3de037..f8724583e6 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -139,7 +139,7 @@ function dl_with_cache($app, $version, $url, $to, $cookies = $null, $use_cache = $cached = cache_path $app $version $url if (!(Test-Path $cached) -or !$use_cache) { - ensure $cachedir | Out-Null + Confirm-DirectoryExistence $SCOOP_CACHE_DIRECTORY | Out-Null do_dl $url "$cached.download" $cookies Move-Item "$cached.download" $cached -Force } else { Write-UserMessage -Message "Loading $(url_remote_filename $url) from cache" } @@ -294,7 +294,7 @@ function dl_with_cache_aria2($app, $version, $manifest, $architecture, $dir, $co if (($url -notlike '*sourceforge.net*') -and ($url -notlike '*portableapps.com*')) { $urlstxt_content += " referer=$(strip_filename $url)`n" } - $urlstxt_content += " dir=$cachedir`n" + $urlstxt_content += " dir=$SCOOP_CACHE_DIRECTORY`n" $urlstxt_content += " out=$($data.$url.cachename)`n" } else { Write-Host 'Loading ' -NoNewline diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 84c25074e8..005f776375 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -306,7 +306,7 @@ function Get-ManifestFromLookup { # Select versioned manifest or generate it if ($requestedVersion) { try { - $path = manifest_path -app $requestedName -bucket $requestedBucket -version $requestedVersion + $path = manifest_path -app $requestedName -bucket $manifestBucket -version $requestedVersion if ($null -eq $path) { throw 'trigger' } $manifestPath = $path } catch { @@ -328,7 +328,12 @@ function Get-ManifestFromLookup { } $name = $requestedName - $manifest = ConvertFrom-Manifest -LiteralPath $manifestPath + $manifest = $null + try { + $manifest = ConvertFrom-Manifest -LiteralPath $manifestPath + } catch { + throw [ScoopException] "'$manifestPath': Invalid manifest ($($_.Exception.Message))" + } return @{ 'Name' = $name diff --git a/libexec/scoop-download.ps1 b/libexec/scoop-download.ps1 index bdc00ab638..ffec9bc8b5 100644 --- a/libexec/scoop-download.ps1 +++ b/libexec/scoop-download.ps1 @@ -25,68 +25,52 @@ $utility = $opt.u, $opt.utility, 'native' | Where-Object { -not [String]::IsNull if (!$application) { Stop-ScoopExecution -Message 'Parameter missing' } if (($utility -eq 'aria2') -and (!(Test-HelperInstalled -Helper Aria2))) { Stop-ScoopExecution -Message 'Aria2 is not installed' } -$architecture = Resolve-ArchitectureParameter -Architecture $opt.a, $opt.arch +$Architecture = Resolve-ArchitectureParameter -Architecture $opt.a, $opt.arch # Add all supported architectures -if ($opt.b -or $opt.'all-architectures') { $architecture = '32bit', '64bit' } +if ($opt.b -or $opt.'all-architectures') { $Architecture = '32bit', '64bit' } #endregion Parameter validation $exitCode = 0 $problems = 0 + foreach ($app in $application) { - # Prevent leaking variables from previous iteration - $cleanAppName = $bucket = $version = $appName = $manifest = $foundBucket = $url = $null - - # TODO: Adopt Resolve-ManifestInformation - $cleanAppName, $bucket, $version = parse_app $app - $appName, $manifest, $foundBucket, $url = Find-Manifest $cleanAppName $bucket - if ($null -eq $bucket) { $bucket = $foundBucket } - - # Handle potential use case, which should not appear, but just in case - # If parsed name/bucket is not same as the provided one - if ((-not $url) -and (($cleanAppName -ne $appName) -or ($bucket -ne $foundBucket))) { - debug $bucket - debug $cleanAppName - debug $foundBucket - debug $appName - - Write-UserMessage -Message 'Found application name or bucket is not same as requested' -Err + $resolved = $null + try { + $resolved = Resolve-ManifestInformation -ApplicationQuery $app + } catch { ++$problems + $title, $body = $_.Exception.Message -split '\|-' + if (!$body) { $body = $title } + Write-UserMessage -Message $body -Err + debug $_.InvocationInfo + if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $appName -Bucket $bucket -Title $title -Body $body } + continue } - # Generate manifest if there is different version in manifest - if (($null -ne $version) -and ($manifest.version -ne $version)) { - try { - $generated = generate_user_manifest $appName $bucket $version - if ($null -eq $generated) { - throw [ScoopException] '' - } - } catch { - Write-UserMessage -Message 'Archived manifest does not exist and version specific manifest cannot be generated with provided version' -Err - ++$problems - - continue - } - $manifest = parse_json $generated - } + debug $resolved - if (-not $version) { $version = $manifest.version } + # TODO: Remove not neeeded variables. Keep them for now just for less changes + $appName = $resolved.Name + $manifest = $resolved.ManifestObject + $bucket = $resolved.Bucket + $version = $manifest.version if ($version -eq 'nightly') { $version = nightly_version (Get-Date) $checkHash = $false } - Write-UserMessage "Starting download for $app" -Color 'Green' + Write-UserMessage "Starting download for '$app'" -Color 'Green' # TODO: Add better text with parsed appname, version, url/bucket $registered = $false # TODO: Rework with proper wrappers after #3149 switch ($utility) { 'aria2' { - foreach ($arch in $architecture) { + foreach ($arch in $Architecture) { try { - dl_with_cache_aria2 $appName $version $manifest $arch $cachedir $manifest.cookie $true $checkHash + dl_with_cache_aria2 $appName $version $manifest $arch $SCOOP_CACHE_DIRECTORY $manifest.cookie $true $checkHash } catch { # Do not count specific architectures or URLs if (!$registered) { @@ -106,7 +90,7 @@ foreach ($app in $application) { } 'native' { - foreach ($arch in $architecture) { + foreach ($arch in $Architecture) { foreach ($url in (url $manifest $arch)) { try { dl_with_cache $appName $version $url $null $manifest.cookie $true diff --git a/test/Scoop-Config.Tests.ps1 b/test/Scoop-Config.Tests.ps1 index 23c74b8cc1..8ed8170a8e 100644 --- a/test/Scoop-Config.Tests.ps1 +++ b/test/Scoop-Config.Tests.ps1 @@ -52,11 +52,11 @@ Describe 'config' -Tag 'Scoop' { <# It "set_config should create a new PSObject and ensure existing directory" { - $scoopConfig = $null - $configFile = "$PSScriptRoot\.scoop" + $SCOOP_CONFIGURATION = $null + $SCOOP_CONFIGURATION_FILE = "$PSScriptRoot\.scoop" - Mock ensure { $PSScriptRoot } -Verifiable -ParameterFilter { $dir -eq (Split-Path -Path $configFile) } - Mock Set-Content { } -Verifiable -ParameterFilter { $Path -eq $configFile } + Mock ensure { $PSScriptRoot } -Verifiable -ParameterFilter { $dir -eq (Split-Path -Path $SCOOP_CONFIGURATION_FILE) } + Mock Set-Content { } -Verifiable -ParameterFilter { $Path -eq $SCOOP_CONFIGURATION_FILE } Mock ConvertTo-Json { '' } -Verifiable -ParameterFilter { $InputObject -is [System.Management.Automation.PSObject] } set_config 'does_not_exist' 'default' @@ -65,17 +65,17 @@ Describe 'config' -Tag 'Scoop' { } It "set_config should remove a value if set to `$null" { - $scoopConfig = New-Object PSObject - $scoopConfig | Add-Member -MemberType NoteProperty -Name 'should_be_removed' -Value 'a_value' - $scoopConfig | Add-Member -MemberType NoteProperty -Name 'should_stay' -Value 'another_value' - $configFile = "$PSScriptRoot\.scoop" + $SCOOP_CONFIGURATION = New-Object PSObject + $SCOOP_CONFIGURATION | Add-Member -MemberType NoteProperty -Name 'should_be_removed' -Value 'a_value' + $SCOOP_CONFIGURATION | Add-Member -MemberType NoteProperty -Name 'should_stay' -Value 'another_value' + $SCOOP_CONFIGURATION_FILE = "$PSScriptRoot\.scoop" - Mock Set-Content { } -Verifiable -ParameterFilter { $Path -eq $configFile } + Mock Set-Content { } -Verifiable -ParameterFilter { $Path -eq $SCOOP_CONFIGURATION_FILE } Mock ConvertTo-Json { '' } -Verifiable -ParameterFilter { $InputObject -is [System.Management.Automation.PSObject] } - $scoopConfig = set_config 'should_be_removed' $null - $scoopConfig.should_be_removed | Should -BeNullOrEmpty - $scoopConfig.should_stay | Should -Be 'another_value' + $SCOOP_CONFIGURATION = set_config 'should_be_removed' $null + $SCOOP_CONFIGURATION.should_be_removed | Should -BeNullOrEmpty + $SCOOP_CONFIGURATION.should_stay | Should -Be 'another_value' Assert-VerifiableMock } From 9d9076e71286cc12bf979aae33e633b250ef728e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sat, 5 Jun 2021 19:27:36 +0200 Subject: [PATCH 03/14] feat(scoop-cat): Adopt Resolve-ManifestInformation (#165) --- CHANGELOG.md | 7 +++ libexec/scoop-cat.ps1 | 49 ++++++++++----------- libexec/scoop-download.ps1 | 2 +- supporting/completion/Scoop-Completion.psm1 | 37 ++++++++++------ supporting/completion/scoop.lua | 2 + 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1a11ec2b6..06ee39ed21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5) + +- **scoop-cat**: Add `-f`, `--format` options +- Adopt new resolve function for parameter passing + - **scoop-cat** + - **scoop-download** + ## [0.6](https://github.com/Ash258/Scoop-Core/milestone/4) ### 0.6-pre4 diff --git a/libexec/scoop-cat.ps1 b/libexec/scoop-cat.ps1 index 445f16b0f2..be5ab32111 100644 --- a/libexec/scoop-cat.ps1 +++ b/libexec/scoop-cat.ps1 @@ -2,7 +2,8 @@ # Summary: Show content of specified manifest(s). # # Options: -# -h, --help Show help for this command. +# -h, --help Show help for this command. +# -f, --format Show manifest in specific format. Json will be considered as default when this parameter is not provided. 'core', 'getopt', 'help', 'Helpers', 'install', 'manifest' | ForEach-Object { . (Join-Path $PSScriptRoot "..\lib\$_.ps1") @@ -10,41 +11,37 @@ $ExitCode = 0 $Problems = 0 -$Options, $Applications, $_err = getopt $args +$Options, $Applications, $_err = getopt $args 'f:' 'format=' if ($_err) { Stop-ScoopExecution -Message "scoop cat: $_err" -ExitCode 2 } if (!$Applications) { Stop-ScoopExecution -Message 'Parameter missing' -Usage (my_usage) } +$Format = $Options.f, $Options.format, 'json' | Where-Object { ! [String]::IsNullOrEmpty($_) } | Select-Object -First 1 +if ($Format -notin $ALLOWED_MANIFEST_EXTENSION) { Stop-ScoopExecution -Message "Format '$Format' is not supported" -ExitCode 2 } + foreach ($app in $Applications) { - # Prevent leaking variables from previous iteration - $cleanAppName = $bucket = $version = $appName = $manifest = $foundBucket = $url = $null - - # TODO: Adopt Resolve-ManifestInformation - $cleanAppName, $bucket, $version = parse_app $app - $appName, $manifest, $foundBucket, $url = Find-Manifest $cleanAppName $bucket - if ($null -eq $bucket) { $bucket = $foundBucket } - - # Handle potential use case, which should not appear, but just in case - # If parsed name/bucket is not same as the provided one - if ((!$url) -and (($cleanAppName -ne $appName) -or ($bucket -ne $foundBucket))) { - debug $bucket - debug $cleanAppName - debug $foundBucket - debug $appName - Write-UserMessage -Message 'Found application name or bucket is not same as requested' -Err + $resolved = $null + try { + $resolved = Resolve-ManifestInformation -ApplicationQuery $app + } catch { ++$Problems + + $title, $body = $_.Exception.Message -split '\|-' + if (!$body) { $body = $title } + Write-UserMessage -Message $body -Err + debug $_.InvocationInfo + if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $appName -Bucket $bucket -Title $title -Body $body } + continue } - if ($manifest) { - Write-UserMessage -Message "Showing manifest for $app" -Color 'Green' + debug $resolved - # TODO: YAML - $manifest | ConvertToPrettyJson | Write-UserMessage -Output - } else { - Write-UserMessage -Message "Manifest for $app not found" -Err - ++$Problems - continue + $output = $resolved.ManifestObject | ConvertTo-Manifest -Extension $Format + + if ($output) { + Write-UserMessage -Message "Showing manifest for '$app'" -Success # TODO: Add better text with parsed appname, version, url/bucket + Write-UserMessage -Message $output -Output } } diff --git a/libexec/scoop-download.ps1 b/libexec/scoop-download.ps1 index ffec9bc8b5..d2aa6ce850 100644 --- a/libexec/scoop-download.ps1 +++ b/libexec/scoop-download.ps1 @@ -53,7 +53,7 @@ foreach ($app in $application) { debug $resolved # TODO: Remove not neeeded variables. Keep them for now just for less changes - $appName = $resolved.Name + $appName = $resolved.ApplicationName $manifest = $resolved.ManifestObject $bucket = $resolved.Bucket $version = $manifest.version diff --git a/supporting/completion/Scoop-Completion.psm1 b/supporting/completion/Scoop-Completion.psm1 index 728b4e2c31..dd09c6eee1 100644 --- a/supporting/completion/Scoop-Completion.psm1 +++ b/supporting/completion/Scoop-Completion.psm1 @@ -42,6 +42,7 @@ $script:SCOOP_SUB_COMMANDS = @{ 'utils' = 'auto-pr checkhashes checkurls checkver describe format missing-checkver' } $script:SCOOP_SHORT_PARAMETERS = @{ + 'cat' = 'f' 'cleanup' = 'g k' 'depends' = 'a' 'download' = 's u a b' @@ -57,6 +58,7 @@ $script:SCOOP_SHORT_PARAMETERS = @{ 'virustotal' = 'a s n' } $script:SCOOP_LONG_PARAMETERS = @{ + 'cat' = 'format' 'cleanup' = 'global cache' 'depends' = 'arch' 'download' = 'skip utility arch all-architectures' @@ -87,28 +89,35 @@ foreach ($cmd in $SCOOP_COMMANDS) { } } +$script:downloadUtilities = 'native aria2' +$script:supportedArchitectures = '64bit 32bit' +$script:supportedManifestFormats = 'json yaml yml' $script:SCOOP_PARAMETER_VALUES = @{ - 'install' = @{ - 'a' = '32bit 64bit' - 'arch' = '32bit 64bit' + 'cat' = @{ + 'f' = $supportedManifestFormats + 'format' = $supportedManifestFormats } 'depends' = @{ - 'a' = '32bit 64bit' - 'arch' = '32bit 64bit' + 'a' = $supportedArchitectures + 'arch' = $supportedArchitectures + } + 'download' = @{ + 'a' = $supportedArchitectures + 'arch' = $supportedArchitectures + 'u' = $downloadUtilities + 'utility' = $downloadUtilities } 'info' = @{ - 'a' = '32bit 64bit' - 'arch' = '32bit 64bit' + 'a' = $supportedArchitectures + 'arch' = $supportedArchitectures } - 'download' = @{ - 'a' = '32bit 64bit' - 'arch' = '32bit 64bit' - 'u' = 'native aria2' - 'utility' = 'native aria2' + 'install' = @{ + 'a' = $supportedArchitectures + 'arch' = $supportedArchitectures } 'virustotal' = @{ - 'a' = '32bit 64bit' - 'arch' = '32bit 64bit' + 'a' = $supportedArchitectures + 'arch' = $supportedArchitectures } } diff --git a/supporting/completion/scoop.lua b/supporting/completion/scoop.lua index 5dfbf342e3..e2c568382d 100644 --- a/supporting/completion/scoop.lua +++ b/supporting/completion/scoop.lua @@ -14,6 +14,7 @@ end local booleanParser = parser({'true', 'false'}) local architectureParser = parser({'32bit', '64bit'}) local utilityParser = parser({'native', 'aria2'}) +local manifestFormatParser = parser({'json', 'yml', 'yaml'}) local configOptions = parser({ '7ZIPEXTRACT_USE_EXTERNAL' .. booleanParser, 'aria2-enabled' .. booleanParser, @@ -152,6 +153,7 @@ local scoopParser = parser({ '-h', '--help' }), 'cat' .. parser({getLocallyAvailableApplicationsByScoop}, + '-f' .. manifestFormatParser, '--format' .. manifestFormatParser, '-h', '--help' ), 'cache' .. parser({'show', 'rm'} .. parser({getScoopCachedFile}), From 0b2373ef82fa0c3e2f828d402bbb67895747c847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sat, 5 Jun 2021 20:36:01 +0200 Subject: [PATCH 04/14] feat(scoop-home): Adopt Resolve-ManifestInformation (#166) --- CHANGELOG.md | 1 + libexec/scoop-cat.ps1 | 1 - libexec/scoop-download.ps1 | 1 - libexec/scoop-home.ps1 | 29 +++++++++++++++++++++-------- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06ee39ed21..12d6aa4739 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - **scoop-cat**: Add `-f`, `--format` options - Adopt new resolve function for parameter passing + - **scoop-home** - **scoop-cat** - **scoop-download** diff --git a/libexec/scoop-cat.ps1 b/libexec/scoop-cat.ps1 index be5ab32111..693257a419 100644 --- a/libexec/scoop-cat.ps1 +++ b/libexec/scoop-cat.ps1 @@ -30,7 +30,6 @@ foreach ($app in $Applications) { if (!$body) { $body = $title } Write-UserMessage -Message $body -Err debug $_.InvocationInfo - if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $appName -Bucket $bucket -Title $title -Body $body } continue } diff --git a/libexec/scoop-download.ps1 b/libexec/scoop-download.ps1 index d2aa6ce850..18814211b8 100644 --- a/libexec/scoop-download.ps1 +++ b/libexec/scoop-download.ps1 @@ -45,7 +45,6 @@ foreach ($app in $application) { if (!$body) { $body = $title } Write-UserMessage -Message $body -Err debug $_.InvocationInfo - if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $appName -Bucket $bucket -Title $title -Body $body } continue } diff --git a/libexec/scoop-home.ps1 b/libexec/scoop-home.ps1 index 6677dfdac3..4f319c2f02 100644 --- a/libexec/scoop-home.ps1 +++ b/libexec/scoop-home.ps1 @@ -16,18 +16,31 @@ $Options, $Application, $_err = getopt $args if ($_err) { Stop-ScoopExecution -Message "scoop home: $_err" -ExitCode 2 } if (!$Application) { Stop-ScoopExecution -Message 'Parameter missing' -Usage (my_usage) } -# TODO: Adopt Resolve-ManifestInformation -$manifest, $null = find_manifest $Application -if ($manifest) { - if ([String]::IsNullOrEmpty($manifest.homepage)) { +$Application = $Application[0] +# Home does not need to generate the manifest as homepage will not change +if ($Application -notmatch '^https?://') { $Application = ($Application -split '@')[0] } + +$resolved = $null +try { + $resolved = Resolve-ManifestInformation -ApplicationQuery $Application +} catch { + $title, $body = $_.Exception.Message -split '\|-' + if (!$body) { $body = $title } + Write-UserMessage -Message $body -Err + debug $_.InvocationInfo + + $ExitCode = 3 +} + +debug $resolved + +if ($ExitCode -eq 0) { + if ([String]::IsNullOrEmpty($resolved.ManifestObject.homepage)) { Write-UserMessage -Message 'Manifest does not contain homepage property' -Err $ExitCode = 3 } else { - Start-Process $manifest.homepage + Start-Process $resolved.ManifestObject.homepage } -} else { - Write-UserMessage -Message "Could not find manifest for '$Application'" -Err - $ExitCode = 3 } exit $ExitCode From 1cec8e2b9b8a4a94a828e2bec4bcce76a2529101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Thu, 10 Jun 2021 20:25:53 +0200 Subject: [PATCH 05/14] ci fix --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index b43c7a22c1..152367dc6f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,6 +2,7 @@ version: "{build}-{branch}" image: Visual Studio 2019 build: off deploy: off +clone_folder: C:\projects\scoop environment: scoop: C:\projects\scoop scoop_home: C:\projects\scoop From 84af13c197128ace8c232bb7268ec9f5646c9eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Thu, 10 Jun 2021 20:27:44 +0200 Subject: [PATCH 06/14] completion --- supporting/completion/Scoop-Completion.psm1 | 4 ++-- supporting/completion/scoop.lua | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/supporting/completion/Scoop-Completion.psm1 b/supporting/completion/Scoop-Completion.psm1 index dd09c6eee1..5404ce558d 100644 --- a/supporting/completion/Scoop-Completion.psm1 +++ b/supporting/completion/Scoop-Completion.psm1 @@ -50,7 +50,7 @@ $script:SCOOP_SHORT_PARAMETERS = @{ 'info' = 'a' 'install' = 'g i k s a' 'list' = 'i u r' - 'search' = 'r' + 'search' = 'a r' 'unhold' = 'g' 'uninstall' = 'g p' 'update' = 'f g i k s q' @@ -66,7 +66,7 @@ $script:SCOOP_LONG_PARAMETERS = @{ 'info' = 'arch' 'install' = 'global independent no-cache skip arch' 'list' = 'installed updated reverse' - 'search' = 'remote' + 'search' = 'api remote' 'unhold' = 'global' 'uninstall' = 'global purge' 'update' = 'force global independent no-cache skip quiet' diff --git a/supporting/completion/scoop.lua b/supporting/completion/scoop.lua index e2c568382d..5ffdab4a88 100644 --- a/supporting/completion/scoop.lua +++ b/supporting/completion/scoop.lua @@ -210,6 +210,7 @@ local scoopParser = parser({ ):loop(1), 'search' .. parser({ '-h', '--help', + '-a', '--api' '-r', '--remote' }), 'status' .. parser({'-h', '--help'}), From d3a0fa858a8d0a5630a92cd250d90690779ea90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Tue, 20 Jul 2021 15:39:36 +0200 Subject: [PATCH 07/14] ch --- CHANGELOG.md | 1 + libexec/scoop-download.ps1 | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 718944ff85..2ebb97d3c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5) - **scoop-search**: + - Add `-a`, `--api` options - Do not fail when parsing invalid local manifest - Support `githubToken` config and `GITHUB_TOKEN` environment variable for Github API calls - **scoop-install**, **scoop-update**: Report failed installations/updates at the end of execution diff --git a/libexec/scoop-download.ps1 b/libexec/scoop-download.ps1 index 2f56971981..658c61a55e 100644 --- a/libexec/scoop-download.ps1 +++ b/libexec/scoop-download.ps1 @@ -41,11 +41,6 @@ foreach ($app in $application) { debug $_.InvocationInfo New-IssuePromptFromException -ExceptionMessage $_.Exception.Message - $title, $body = $_.Exception.Message -split '\|-' - if (!$body) { $body = $title } - Write-UserMessage -Message $body -Err - debug $_.InvocationInfo - continue } From 8aab40f6ef23f97e5b2bde22f2b278b3ec665eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 8 Aug 2021 20:17:48 +0200 Subject: [PATCH 08/14] sync --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7906bbe42..1617260702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5) +- **Checkver**: URL ping behaviour equality with `dl` function - Add `Base` bucket to known - **scoop-checkup**: Do not suggest 7zip installation when `7ZIPEXTRACT_USE_EXTERNAL` is configured - **scoop-search**: From 7785edc408e8103d318aee1b0314f25d52168036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 12 Sep 2021 02:08:58 +0200 Subject: [PATCH 09/14] config shovelSearchAPI; debug --- lib/Search.ps1 | 29 ++++++++++++++++++++++++++++- libexec/scoop-config.ps1 | 4 ++++ libexec/scoop-search.ps1 | 16 ++++++++++++++++ supporting/completion/scoop.lua | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/Search.ps1 b/lib/Search.ps1 index df413beb32..0f229716b4 100644 --- a/lib/Search.ps1 +++ b/lib/Search.ps1 @@ -222,7 +222,34 @@ function Search-RemoteAPI { param([String] $Query) process { - $res = Invoke-RestMethod -Uri "https://api.shovel.ash258.com/api/v1/?query=$Query&size=10000&page=0" + $api = get_config 'shovelSearchAPI' 'https://api/shovel.ash258.com/api/v1' + + $buckets = @() + $res = @{} + try { + $buckets = Invoke-RestMethod -Uri "$api/bucket?size=10000&page=0" + } catch { + throw "Cannot get buckets information from API: $($_.Exception.Message)" + } + try { + $res = Invoke-RestMethod -Uri "$api/manifest/search?query=$Query&size=10000&page=0" + } catch { + throw "Cannot get manifests from API: $($_.Exception.Message)" + } + + Write-Host $buckets -f green + Write-Host $res -f green + + # TODO: Process results + # $apps += @{ + # 'name' = $resolved.ApplicationName + # 'version' = $manifest.version + # 'description' = $manifest.description + # 'bin' = @(arch_specific 'bin' $manifest $architecture) + # 'matchingBinaries' = @() + # 'shortcuts' = @(arch_specific 'shortcuts' $manifest $architecture) + # 'matchingShortcuts' = @() + # } return $res.content } diff --git a/libexec/scoop-config.ps1 b/libexec/scoop-config.ps1 index db1cc457fe..adf9d0b9ba 100644 --- a/libexec/scoop-config.ps1 +++ b/libexec/scoop-config.ps1 @@ -75,6 +75,10 @@ # GitHub API token used for checkver/autoupdate runs to prevent rate limiting. # See: 'https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token' # +# shovelSearchAPI: +# Provide alternative search API for shovel. Mainly for debugging. +# Has to be full API URL. Including protocol, API version. +# # ARIA2 configuration # ------------------- # diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index f9d30df389..88c6a18ce0 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -22,9 +22,25 @@ $Options, $Query, $_err = Resolve-GetOpt $args 'ra' 'remote', 'api' if ($_err) { Stop-ScoopExecution -Message "scoop search: $_err" -ExitCode 2 } +$Query = $Query[0] $Remote = $Options.r -or $Options.remote $Api = $Options.a -or $Options.api +if ($Api) { + try { + $results = Search-RemoteAPI -Query $Query + } catch { + Stop-ScoopExecution -Message "scoop search: $_" -ExitCode 3 + } + + # TODO: Bucket url + # TODO: Prompt for bucket addition + $results | ForEach-Object { + Write-Host "$($_.name) ($($_.version)) - URL - remote URL" -f red + } +} +exit 0 + if ($Query) { try { $Query = New-Object System.Text.RegularExpressions.Regex $Query, 'IgnoreCase' diff --git a/supporting/completion/scoop.lua b/supporting/completion/scoop.lua index 7243173850..04a4409a59 100644 --- a/supporting/completion/scoop.lua +++ b/supporting/completion/scoop.lua @@ -34,6 +34,7 @@ local configOptions = parser({ 'virustotal_api_key', 'proxy', 'githubToken' + 'shovelSearchAPI' }) -- region Functions From 13310d656b3b57bf144c50fd1360c84e9ad469a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sun, 12 Sep 2021 02:31:21 +0200 Subject: [PATCH 10/14] wip --- lib/Search.ps1 | 6 ++++-- libexec/scoop-config.ps1 | 2 +- libexec/scoop-search.ps1 | 7 +++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/Search.ps1 b/lib/Search.ps1 index 0f229716b4..c24d21e5ce 100644 --- a/lib/Search.ps1 +++ b/lib/Search.ps1 @@ -237,9 +237,11 @@ function Search-RemoteAPI { throw "Cannot get manifests from API: $($_.Exception.Message)" } - Write-Host $buckets -f green - Write-Host $res -f green + # Write-Host $buckets -f green + # Write-Host $res -f green + # TODO: test if bucket is added + # TODO: test if bucket is known # TODO: Process results # $apps += @{ # 'name' = $resolved.ApplicationName diff --git a/libexec/scoop-config.ps1 b/libexec/scoop-config.ps1 index adf9d0b9ba..36ecdc5c02 100644 --- a/libexec/scoop-config.ps1 +++ b/libexec/scoop-config.ps1 @@ -76,7 +76,7 @@ # See: 'https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token' # # shovelSearchAPI: -# Provide alternative search API for shovel. Mainly for debugging. +# Provide alternative search API for Shovel. Mainly for debugging. # Has to be full API URL. Including protocol, API version. # # ARIA2 configuration diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index 88c6a18ce0..096ee96dbc 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -36,7 +36,7 @@ if ($Api) { # TODO: Bucket url # TODO: Prompt for bucket addition $results | ForEach-Object { - Write-Host "$($_.name) ($($_.version)) - URL - remote URL" -f red + Write-Host "$($_.name)@$($_.version) - $($_.url)" -f Magenta } } exit 0 @@ -109,10 +109,9 @@ if (!$Api -and (!$LocalResults -or $Remote)) { if ($Api) { $results = Search-RemoteAPI -Query $Query - # TODO: Bucket url - # TODO: Prompt for bucket addition + exit 258 $results | ForEach-Object { - Write-Host "$($_.name) ($($_.version)) - URL - remote URL" -f red + Write-Host "$($_.name)@$($_.version) - $($_.url)" -f red } } From d38d7b7c2a4ab6fede12c6a44657d051f3aeee25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Mon, 13 Sep 2021 21:39:39 +0200 Subject: [PATCH 11/14] pagination --- lib/Search.ps1 | 29 ++++++++++++++++++----------- libexec/scoop-search.ps1 | 4 ++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/Search.ps1 b/lib/Search.ps1 index c24d21e5ce..3a1205b323 100644 --- a/lib/Search.ps1 +++ b/lib/Search.ps1 @@ -219,26 +219,33 @@ function Search-LocalBucket { function Search-RemoteAPI { [CmdletBinding()] - param([String] $Query) + param([String] $Query = '%') process { - $api = get_config 'shovelSearchAPI' 'https://api/shovel.ash258.com/api/v1' + if ([String]::IsNullOrEmpty($Query)) { $Query = '%' } - $buckets = @() + $api = get_config 'shovelSearchAPI' 'https://api/shovel.ash258.com/api/v1' $res = @{} + $buckets = @() try { $buckets = Invoke-RestMethod -Uri "$api/bucket?size=10000&page=0" } catch { throw "Cannot get buckets information from API: $($_.Exception.Message)" } - try { - $res = Invoke-RestMethod -Uri "$api/manifest/search?query=$Query&size=10000&page=0" - } catch { - throw "Cannot get manifests from API: $($_.Exception.Message)" - } - # Write-Host $buckets -f green - # Write-Host $res -f green + $final = @() + $page = $total = 0 + + do { + try { + $res = Invoke-RestMethod -Uri "$api/manifest/search?query=$Query&size=1000&page=$page" + } catch { + throw "Cannot get manifests from API: $($_.Exception.Message)" + } + $total = $res.total + ++$page + $final += $res.content + } while ($total -ne $final.Count) # TODO: test if bucket is added # TODO: test if bucket is known @@ -253,6 +260,6 @@ function Search-RemoteAPI { # 'matchingShortcuts' = @() # } - return $res.content + return $final } } diff --git a/libexec/scoop-search.ps1 b/libexec/scoop-search.ps1 index 096ee96dbc..fa7936986c 100644 --- a/libexec/scoop-search.ps1 +++ b/libexec/scoop-search.ps1 @@ -35,6 +35,10 @@ if ($Api) { # TODO: Bucket url # TODO: Prompt for bucket addition + if ($results.Count -eq 0) { + Write-Host "No results found for query '$Query'" + } + $results | ForEach-Object { Write-Host "$($_.name)@$($_.version) - $($_.url)" -f Magenta } From 0c712a833125e548bcd0fd1edca3657e8632916f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Tue, 26 Oct 2021 21:09:38 +0200 Subject: [PATCH 12/14] typo, deprecated --- lib/Search.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Search.ps1 b/lib/Search.ps1 index 2fde253139..1057258f60 100644 --- a/lib/Search.ps1 +++ b/lib/Search.ps1 @@ -233,10 +233,11 @@ function Search-RemoteAPI { process { if ([String]::IsNullOrEmpty($Query)) { $Query = '%' } - $api = get_config 'shovelSearchAPI' 'https://api/shovel.ash258.com/api/v1' + $api = get_config 'shovelSearchAPI' 'https://api.shovel.ash258.com/api/v1' $res = @{} $buckets = @() try { + # TODO: Pagination just for the convenience $buckets = Invoke-RestMethod -Uri "$api/bucket?size=10000&page=0" } catch { throw "Cannot get buckets information from API: $($_.Exception.Message)" @@ -251,13 +252,14 @@ function Search-RemoteAPI { } catch { throw "Cannot get manifests from API: $($_.Exception.Message)" } - $total = $res.total ++$page + $total = $res.total $final += $res.content } while ($total -ne $final.Count) # TODO: test if bucket is added # TODO: test if bucket is known + # TODO: Remove deprecated # TODO: Process results # $apps += @{ # 'name' = $resolved.ApplicationName From bb483b4fef8fb0a230e27d03109700b1cc72449e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Wed, 8 Dec 2021 21:18:13 +0100 Subject: [PATCH 13/14] ch --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c12e8f38ab..8de0481c17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 🎉🎉 YAML typed manifest and archived manifest installation support 🎉🎉 +- **scoop-search**: Add `-a`, `--api` paramters - **scoop-uninstall**: Warn user when he tries to uninstall dependency, which is still needed - **scoop-status**: Detect if applications, which were installed as dependency are still needed - **scoop-list**: Show if application was installed as dependency @@ -55,7 +56,6 @@ - It will be automatically added when `update` command is executed - **scoop-checkup**: Do not suggest 7zip installation when `7ZIPEXTRACT_USE_EXTERNAL` is configured - **scoop-search**: - - Add `-a`, `--api` options - Do not fail when parsing invalid local manifest - Support `githubToken` config and `GITHUB_TOKEN` environment variable for Github API calls - **scoop-install**, **scoop-update**: Report failed installations/updates at the end of execution From a67bc3ee632a4ed14abd364578b4834db34e5b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8C=C3=A1bera?= Date: Sat, 26 Feb 2022 11:34:31 +0100 Subject: [PATCH 14/14] ch --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7186760f38..7b48dff65b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5) +- **scoop-search**: Add `-a`, `--api` paramters - Support installation of archives under *nix - **psmodules**: Fix uninstallation - **Unix**: Use short option for symbolic `ln` calls @@ -26,7 +27,6 @@ 🎉🎉 YAML typed manifest and archived manifest installation support 🎉🎉 -- **scoop-search**: Add `-a`, `--api` paramters - Prompt for the new issue now has correct version in title in case of archived manifest is being downloaded/installed/... - **Unix**: - Fix `--version` command under *nix