-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor(search): Improve search output and ratelimit handling #3446
Conversation
9ddd828
to
89c93d6
Compare
The shortcut searching was inspired by ScoopInstaller/Extras#2227 because @ssfjhh couldn't find I also improved the output to be more readable: |
|
||
$results = $names | Where-Object { !(test-path $(Find-BucketDirectory $_)) } | ForEach-Object { | ||
@{"bucket" = $_; "results" = (search_remote $_ $query)} | ||
$results = known_buckets | Where-Object { !(test-path $(Find-BucketDirectory $_)) } | ForEach-Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for subshell
$results = known_buckets | Where-Object { !(test-path $(Find-BucketDirectory $_)) } | ForEach-Object { | |
$results = known_buckets | Where-Object { !(Test-Path (Find-BucketDirectory $_)) } | ForEach-Object { |
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
Co-Authored-By: Jakub Čábera <cabera.jakub@gmail.com>
param( | ||
[Parameter(Mandatory = $true)] | ||
$Query, | ||
[Switch] $Remote |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing documentation for this parameter.
Why is this parameter needed? I would expect that if this is specified ONLY remotes are searched. But locals are searched all the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Query is now mandatory. Change documentation for help command, reflecting this change.
Write-Host 'Searching in local buckets ...' | ||
$local_results = @() | ||
|
||
foreach ($bucket in (Get-LocalBucket) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing bracket
foreach ($bucket in (Get-LocalBucket) { | |
foreach ($bucket in (Get-LocalBucket)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
foreach ($shortcut in $app.shortcuts) { | ||
if($shortcut -is [Array] -and $shortcut.length -ge 2) { | ||
$name = $shortcut[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$name = $shortcut[1] | |
$executable = $shortcut[0] | |
$name = $shortcut[1] |
foreach ($shortcut in $app.shortcuts) { | ||
if($shortcut -is [Array] -and $shortcut.length -ge 2) { | ||
$name = $shortcut[1] | ||
if($name -match $query) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if($name -match $query) { | |
if ($name -match $query -or $executable -match $query) { |
foreach ($bucket in (Get-LocalBucket) { | ||
$result = search_bucket $bucket $query | ||
if(!$result) { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect you do not want to break on first bucket, which do not have results
return | |
continue |
Would be possible to move functions into |
I think more user-friendly it would be to follow getopt way for parameters. Now you will get this: You could go rather with optional query param and then manual check 'getopt', 'manifest', 'install', 'versions', 'config' | ForEach-Object {
. "$PSScriptRoot\..\lib\$_.ps1"
}
$Remote = $false
$opt, $Query, $err = getopt $args 'r' 'remote'
if (-not $Query) { error 'QUERY IS NEEDED'; exit 1 }
if ($opt.r -or $opt.remote) { $Remote = $true } |
try { | ||
$query = New-Object Regex $query, 'IgnoreCase' | ||
} catch { | ||
abort "Invalid regular expression: $($_.exception.innerexception.message)" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this outside function. When it will be standalone inside scoop-search.ps1
you will save abort call and can handle failsafe scenario better.
Then the query, which is passing into search_bucket
function could be Regex object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also you do not need to create regex for each bucket. This regex is same for all buckets
Superceded by #4997 |
Invoke-RestMethod
X-RateLimit-Remaining
returned by GitHub, PowerShell 6 only)Related #3853