mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2026-08-26 08:06:36 +00:00
[buckets] Optimize buckets function (#3341)
* Optimize buckets function * Use Verb-Noun naming * Add Show-DeprecatedWarning function to core
This commit is contained in:
committed by
Richard Kuhnt
parent
2181438ce2
commit
4463514948
+1
-1
@@ -19,7 +19,7 @@ if ('--version' -contains $cmd -or (!$cmd -and '-v' -contains $args)) {
|
||||
write-host ""
|
||||
Pop-Location
|
||||
|
||||
buckets | ForEach-Object {
|
||||
Get-LocalBucket | ForEach-Object {
|
||||
Push-Location $(bucketdir $_)
|
||||
if(test-path '.git') {
|
||||
write-host "'$_' bucket:"
|
||||
|
||||
+15
-6
@@ -1,3 +1,5 @@
|
||||
. "$PSScriptRoot\core.ps1"
|
||||
|
||||
$bucketsdir = "$scoopdir\buckets"
|
||||
|
||||
<#
|
||||
@@ -39,12 +41,19 @@ function apps_in_bucket($dir) {
|
||||
return Get-ChildItem $dir | Where-Object { $_.Name.endswith('.json') } | ForEach-Object { $_.Name -replace '.json$', '' }
|
||||
}
|
||||
|
||||
function Get-LocalBucket {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
List all local buckets.
|
||||
#>
|
||||
|
||||
return (Get-ChildItem $bucketsdir).Name
|
||||
}
|
||||
|
||||
function buckets {
|
||||
$buckets = @()
|
||||
if(test-path $bucketsdir) {
|
||||
Get-ChildItem $bucketsdir | ForEach-Object { $buckets += $_.Name }
|
||||
}
|
||||
return $buckets
|
||||
Show-DeprecatedWarning $MyInvocation 'Get-LocalBucket'
|
||||
|
||||
return Get-LocalBucket
|
||||
}
|
||||
|
||||
function find_manifest($app, $bucket) {
|
||||
@@ -54,7 +63,7 @@ function find_manifest($app, $bucket) {
|
||||
return $null
|
||||
}
|
||||
|
||||
$buckets = @($null) + @(buckets) # null for main bucket
|
||||
$buckets = @($null) + @(Get-LocalBucket) # null for main bucket
|
||||
foreach($bucket in $buckets) {
|
||||
$manifest = manifest $app $bucket
|
||||
if($manifest) { return $manifest, $bucket }
|
||||
|
||||
@@ -42,6 +42,22 @@ function Get-UserAgent() {
|
||||
return "Scoop/1.0 (+http://scoop.sh/) PowerShell/$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor) (Windows NT $([System.Environment]::OSVersion.Version.Major).$([System.Environment]::OSVersion.Version.Minor); $(if($env:PROCESSOR_ARCHITECTURE -eq 'AMD64'){'Win64; x64; '})$(if($env:PROCESSOR_ARCHITEW6432 -eq 'AMD64'){'WOW64; '})$PSEdition)"
|
||||
}
|
||||
|
||||
function Show-DeprecatedWarning {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Print deprecated warning for functions, which will be deleted in near future.
|
||||
.PARAMETER Invocation
|
||||
Invocation to identify location of line.
|
||||
Just pass $MyInvocation.
|
||||
.PARAMETER New
|
||||
New command name.
|
||||
#>
|
||||
param($Invocation, [String] $New)
|
||||
|
||||
warn ('"{0}" will be deprecated. Please change your code/manifest to use "{1}"' -f $Invocation.MyCommand.Name, $New)
|
||||
Write-Host " -> $($Invocation.PSCommandPath):$($Invocation.ScriptLineNumber):$($Invocation.OffsetInLine)" -ForegroundColor DarkGray
|
||||
}
|
||||
|
||||
# helper functions
|
||||
function coalesce($a, $b) { if($a) { return $a } $b }
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ function dep_resolve($app, $arch, $resolved, $unresolved) {
|
||||
$null, $manifest, $null, $null = locate $app $bucket
|
||||
|
||||
if(!$manifest) {
|
||||
if(((buckets) -notcontains $bucket) -and $bucket) {
|
||||
if(((Get-LocalBucket) -notcontains $bucket) -and $bucket) {
|
||||
warn "Bucket '$bucket' not installed. Add it with 'scoop bucket add $bucket' or 'scoop bucket add $bucket <repo>'."
|
||||
}
|
||||
abort "Couldn't find manifest for '$app'$(if(!$bucket) { '.' } else { " from '$bucket' bucket." })"
|
||||
|
||||
@@ -32,7 +32,7 @@ $usage_rm = "usage: scoop bucket rm <name>"
|
||||
switch($cmd) {
|
||||
'add' { add_bucket $name $repo }
|
||||
'rm' { rm_bucket $name }
|
||||
'list' { buckets }
|
||||
'list' { Get-LocalBucket }
|
||||
'known' { known_buckets }
|
||||
default { "scoop bucket: cmd '$cmd' not supported"; my_usage; exit 1 }
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ function search_remotes($query) {
|
||||
}
|
||||
}
|
||||
|
||||
@($null) + @(buckets) | ForEach-Object { # $null is main bucket
|
||||
@($null) + @(Get-LocalBucket) | ForEach-Object { # $null is main bucket
|
||||
$res = search_bucket $_ $query
|
||||
$local_results = $local_results -or $res
|
||||
if($res) {
|
||||
|
||||
@@ -100,7 +100,7 @@ function update_scoop() {
|
||||
ensure_scoop_in_path
|
||||
shim "$currentdir\bin\scoop.ps1" $false
|
||||
|
||||
@(buckets) | ForEach-Object {
|
||||
Get-LocalBucket | ForEach-Object {
|
||||
write-host "Updating '$_' bucket..."
|
||||
Push-Location (bucketdir $_)
|
||||
git_pull -q
|
||||
|
||||
Reference in New Issue
Block a user