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-search): Add --api, -a option #150

Draft
wants to merge 37 commits into
base: NEW
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
45e8c30
feat(scoop-search): Add --api, -a option
Ash258 May 16, 2021
aa017b0
feat(scoop-download): Adopt Resolve-ManifestInformation (#164)
Ash258 Jun 5, 2021
9d9076e
feat(scoop-cat): Adopt Resolve-ManifestInformation (#165)
Ash258 Jun 5, 2021
0b2373e
feat(scoop-home): Adopt Resolve-ManifestInformation (#166)
Ash258 Jun 5, 2021
d0da8d3
Merge branch 'NEW' of https://github.com/Ash258/Scoop-Core into featS…
Ash258 Jun 10, 2021
1cec8e2
ci fix
Ash258 Jun 10, 2021
84af13c
completion
Ash258 Jun 10, 2021
9583dcb
Merge branch 'main' of https://github.com/Ash258/Scoop-Core into NEW
Ash258 Jun 10, 2021
01d256f
Merge branch 'NEW' of https://github.com/Ash258/Scoop-Core into featS…
Ash258 Jun 10, 2021
6164f36
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featSearchAPI
Ash258 Jul 20, 2021
d3a0fa8
ch
Ash258 Jul 20, 2021
4979b43
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featSearchAPI
Ash258 Aug 8, 2021
8aab40f
sync
Ash258 Aug 8, 2021
1bb28f3
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featSearchAPI
Ash258 Aug 15, 2021
7ed71b4
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featSearchAPI
Ash258 Sep 11, 2021
7785edc
config shovelSearchAPI; debug
Ash258 Sep 12, 2021
13310d6
wip
Ash258 Sep 12, 2021
d38d7b7
pagination
Ash258 Sep 13, 2021
908eac8
Merge branch 'NEW' of https://github.com/Ash258/Scoop-Core into featS…
Ash258 Oct 26, 2021
0c712a8
typo, deprecated
Ash258 Oct 26, 2021
4785b16
Merge branch 'NEW' into featSearchAPI
Ash258 Oct 31, 2021
c83cc2b
Merge branch 'NEW' into featSearchAPI
Ash258 Nov 22, 2021
b18adb3
Merge branch 'NEW' into featSearchAPI
Ash258 Nov 24, 2021
df7d6e1
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featSearchAPI
Ash258 Dec 4, 2021
79e1a9d
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featSearchAPI
Ash258 Dec 8, 2021
bb483b4
ch
Ash258 Dec 8, 2021
f921446
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featSearchAPI
Ash258 Dec 15, 2021
2dd259d
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featSearchAPI
Ash258 Dec 18, 2021
6325f0a
Merge branch 'NEW' into featSearchAPI
Ash258 Dec 29, 2021
6a90e6d
Merge branch 'NEW' into featSearchAPI
Ash258 Jan 28, 2022
bc68613
Merge branch 'NEW' into featSearchAPI
Ash258 Jan 29, 2022
aed8456
Merge branch 'NEW' into featSearchAPI
Ash258 Feb 9, 2022
bfeb3a1
Merge branch 'NEW' into featSearchAPI
Ash258 Feb 12, 2022
8d16176
Merge branch 'NEW' into featSearchAPI
Ash258 Feb 25, 2022
a0c24ab
Merge branch 'NEW' into featSearchAPI
Ash258 Feb 25, 2022
a67bc3e
ch
Ash258 Feb 26, 2022
b978021
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into featSearchAPI
Ash258 Jul 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5)

- **scoop-search**: Add `-a`, `--api` paramters
- **Tests**: Fix detection of 1 new line at the end and allow CRLF/LF for powershell executables
- **MacOS**: Properly detect arm architecture
- Support installation of archives under *nix
Expand Down
49 changes: 49 additions & 0 deletions lib/Search.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,53 @@ function Search-LocalBucket {
end { return $result }
}

function Search-RemoteAPI {
[CmdletBinding()]
param([String] $Query = '%')

process {
if ([String]::IsNullOrEmpty($Query)) { $Query = '%' }

$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)"
}

$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)"
}
++$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
# 'version' = $manifest.version
# 'description' = $manifest.description
# 'bin' = @(arch_specific 'bin' $manifest $architecture)
# 'matchingBinaries' = @()
# 'shortcuts' = @(arch_specific 'shortcuts' $manifest $architecture)
# 'matchingShortcuts' = @()
# }

return $final
}
}

$__importedSearch__ = $true
4 changes: 4 additions & 0 deletions libexec/scoop-config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
# dbgBypassArmCheck: $true|$false
# Do not fail to install arm64 version on x86 platform.
#
# shovelSearchAPI:
# Provide alternative search API for Shovel. Mainly for debugging.
# Has to be full API URL. Including protocol, API version.
#
# ARIA2 configuration
# -------------------
#
Expand Down
37 changes: 35 additions & 2 deletions libexec/scoop-search.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,42 @@
# -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.

'core', 'getopt', 'help', 'Helpers', 'buckets', 'Search' | ForEach-Object {
. (Join-Path $PSScriptRoot "..\lib\${_}.ps1")
}

$ExitCode = 0
$LocalResults = @()
$Options, $Query, $_err = Resolve-GetOpt $args 'r' 'remote'
$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
if ($results.Count -eq 0) {
Write-Host "No results found for query '$Query'"
}

$results | ForEach-Object {
Write-Host "$($_.name)@$($_.version) - $($_.url)" -f Magenta
}
}
exit 0

if ($Query) {
try {
Expand Down Expand Up @@ -67,7 +91,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-UserMessage -Message 'Searching in remote buckets ...'
$remoteResults = Search-AllRemote -Query $Query
Expand All @@ -86,4 +110,13 @@ if (!$LocalResults -or $Remote) {
}
}

if ($Api) {
$results = Search-RemoteAPI -Query $Query

exit 258
$results | ForEach-Object {
Write-Host "$($_.name)@$($_.version) - $($_.url)" -f red
}
}

exit $ExitCode
4 changes: 2 additions & 2 deletions supporting/completion/Scoop-Completion.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions supporting/completion/scoop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ local configOptions = parser({
'virustotal_api_key',
'proxy',
'githubToken'
'shovelSearchAPI'
})

-- region Functions
Expand Down Expand Up @@ -216,6 +217,7 @@ local scoopParser = parser({
):loop(1),
'search' .. parser({
'-h', '--help',
'-a', '--api'
'-r', '--remote'
}),
'status' .. parser({'-h', '--help'}),
Expand Down