mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
feat(aur): customize User Agent
This commit is contained in:
parent
6e70e2a59d
commit
545ea772eb
2
clean.go
2
clean.go
@ -116,7 +116,7 @@ func cleanAUR(keepInstalled, keepCurrent, removeAll bool, dbExecutor db.Executor
|
||||
// Querying the AUR is slow and needs internet so don't do it if we
|
||||
// don't need to.
|
||||
if keepCurrent {
|
||||
info, errInfo := query.AURInfo(cachedPackages, &query.AURWarnings{}, config.RequestSplitN)
|
||||
info, errInfo := query.AURInfo(config.Runtime.AURClient, cachedPackages, &query.AURWarnings{}, config.RequestSplitN)
|
||||
if errInfo != nil {
|
||||
return errInfo
|
||||
}
|
||||
|
4
cmd.go
4
cmd.go
@ -291,7 +291,7 @@ func handleSync(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
||||
} else {
|
||||
config.SearchMode = detailed
|
||||
}
|
||||
return syncSearch(targets, dbExecutor)
|
||||
return syncSearch(targets, config.Runtime.AURClient, dbExecutor)
|
||||
}
|
||||
if cmdArgs.ExistsArg("p", "print", "print-format") {
|
||||
return config.Runtime.CmdRunner.Show(passToPacman(cmdArgs))
|
||||
@ -341,7 +341,7 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *settings.
|
||||
pkgS = query.RemoveInvalidTargets(pkgS, config.Runtime.Mode)
|
||||
|
||||
if config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny {
|
||||
aq, aurErr = narrowSearch(pkgS, true)
|
||||
aq, aurErr = narrowSearch(config.Runtime.AURClient, pkgS, true)
|
||||
lenaq = len(aq)
|
||||
}
|
||||
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
|
||||
|
@ -164,7 +164,7 @@ func getPkgbuilds(pkgs []string, dbExecutor db.Executor, force bool) error {
|
||||
aur[n] = pkg
|
||||
}
|
||||
|
||||
info, err := query.AURInfoPrint(aur, config.RequestSplitN)
|
||||
info, err := query.AURInfoPrint(config.Runtime.AURClient, aur, config.RequestSplitN)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
9
go.mod
9
go.mod
@ -1,19 +1,18 @@
|
||||
module github.com/Jguer/yay/v10
|
||||
|
||||
require (
|
||||
github.com/Jguer/aur v0.0.0-20210511064249-3d6117992c83
|
||||
github.com/Jguer/go-alpm/v2 v2.0.5
|
||||
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5
|
||||
github.com/Morganamilo/go-srcinfo v1.0.0
|
||||
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/leonelquinteros/gotext v1.4.0
|
||||
github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656
|
||||
github.com/leonelquinteros/gotext v1.5.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096
|
||||
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56
|
||||
golang.org/x/text v0.3.6 // indirect
|
||||
gopkg.in/h2non/gock.v1 v1.0.15
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
)
|
||||
|
||||
go 1.14
|
||||
|
25
go.sum
25
go.sum
@ -1,3 +1,7 @@
|
||||
github.com/Jguer/aur v0.0.0-20210510203355-38871b878ace h1:7ImlMwhRXVtuE+4jjEut4GCdNUGFyuytQUIxyCyy218=
|
||||
github.com/Jguer/aur v0.0.0-20210510203355-38871b878ace/go.mod h1:1/SQjhWahmk2xKcmAm6XO1zGqK8HgYw3xlJM6a7845E=
|
||||
github.com/Jguer/aur v0.0.0-20210511064249-3d6117992c83 h1:UtnJ3lvuidbG5rwN2tSQe5kVOvhFZRUGNkS6boxgxPk=
|
||||
github.com/Jguer/aur v0.0.0-20210511064249-3d6117992c83/go.mod h1:1/SQjhWahmk2xKcmAm6XO1zGqK8HgYw3xlJM6a7845E=
|
||||
github.com/Jguer/go-alpm/v2 v2.0.5 h1:1TZxkvCIfTOhjhxGy/Z1FNSeuY9DXBKF5qxUoj0IZ0A=
|
||||
github.com/Jguer/go-alpm/v2 v2.0.5/go.mod h1:zU4iKCtNkDARfj5BrKJXYAQ5nIjtZbySfa0paboSmTQ=
|
||||
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5 h1:TMscPjkb1ThXN32LuFY5bEYIcXZx3YlwzhS1GxNpn/c=
|
||||
@ -13,22 +17,39 @@ github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslC
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
|
||||
github.com/leonelquinteros/gotext v1.4.0 h1:2NHPCto5IoMXbrT0bldPrxj0qM5asOCwtb1aUQZ1tys=
|
||||
github.com/leonelquinteros/gotext v1.4.0/go.mod h1:yZGXREmoGTtBvZHNcc+Yfug49G/2spuF/i/Qlsvz1Us=
|
||||
github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656 h1:j679+jxcDkCFblYk+I+G71HQTFxM3PacYbVCiYmhRhU=
|
||||
github.com/mikkeloscar/aur v0.0.0-20200113170522-1cb4e2949656/go.mod h1:nYOKcK8tIj69ZZ8uDOWoiT+L25NvlOQaraDqTec/idA=
|
||||
github.com/leonelquinteros/gotext v1.5.0 h1:ODY7LzLpZWWSJdAHnzhreOr6cwLXTAmc914FOauSkBM=
|
||||
github.com/leonelquinteros/gotext v1.5.0/go.mod h1:OCiUVHuhP9LGFBQ1oAmdtNCHJCiHiQA8lf4nAifHkr0=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096 h1:5PbJGn5Sp3GEUjJ61aYbUP6RIo3Z3r2E4Tv9y2z8UHo=
|
||||
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 h1:yhBbb4IRs2HS9PPlAg6DMC6mUOKexJBNsLf4Z+6En1Q=
|
||||
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
|
||||
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20200221224223-e1da425f72fd/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0=
|
||||
|
@ -140,7 +140,7 @@ func install(cmdArgs *settings.Arguments, dbExecutor db.Executor, ignoreProvider
|
||||
targets := stringset.FromSlice(cmdArgs.Targets)
|
||||
|
||||
dp, err := dep.GetPool(requestTargets,
|
||||
warnings, dbExecutor, config.Runtime.Mode,
|
||||
warnings, dbExecutor, config.Runtime.AURClient, config.Runtime.Mode,
|
||||
ignoreProviders, settings.NoConfirm, config.Provides, config.ReBuild, config.RequestSplitN, noDeps, noCheck)
|
||||
if err != nil {
|
||||
return err
|
||||
|
2
main.go
2
main.go
@ -89,7 +89,7 @@ func main() {
|
||||
text.Warnln(gotext.Get("Avoid running yay as root/sudo."))
|
||||
}
|
||||
|
||||
config, err = settings.NewConfig()
|
||||
config, err = settings.NewConfig(yayVersion)
|
||||
if err != nil {
|
||||
if str := err.Error(); str != "" {
|
||||
fmt.Fprintln(os.Stderr, str)
|
||||
|
@ -1,9 +1,9 @@
|
||||
package dep
|
||||
|
||||
import rpc "github.com/Jguer/yay/v10/pkg/query"
|
||||
import aur "github.com/Jguer/yay/v10/pkg/query"
|
||||
|
||||
// Base is an AUR base package
|
||||
type Base []*rpc.Pkg
|
||||
type Base []*aur.Pkg
|
||||
|
||||
// Pkgbase returns the first base package.
|
||||
func (b Base) Pkgbase() string {
|
||||
@ -38,7 +38,7 @@ func (b Base) String() string {
|
||||
return str
|
||||
}
|
||||
|
||||
func GetBases(pkgs []*rpc.Pkg) []Base {
|
||||
func GetBases(pkgs []*aur.Pkg) []Base {
|
||||
basesMap := make(map[string]Base)
|
||||
for _, pkg := range pkgs {
|
||||
basesMap[pkg.PackageBase] = append(basesMap[pkg.PackageBase], pkg)
|
||||
|
@ -4,19 +4,19 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
rpc "github.com/Jguer/yay/v10/pkg/query"
|
||||
aur "github.com/Jguer/yay/v10/pkg/query"
|
||||
"github.com/Jguer/yay/v10/pkg/text"
|
||||
)
|
||||
|
||||
type providers struct {
|
||||
lookfor string
|
||||
Pkgs []*rpc.Pkg
|
||||
Pkgs []*aur.Pkg
|
||||
}
|
||||
|
||||
func makeProviders(name string) providers {
|
||||
return providers{
|
||||
name,
|
||||
make([]*rpc.Pkg, 0),
|
||||
make([]*aur.Pkg, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ func verSatisfies(ver1, mod, ver2 string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func satisfiesAur(dep string, pkg *rpc.Pkg) bool {
|
||||
func satisfiesAur(dep string, pkg *aur.Pkg) bool {
|
||||
if pkgSatisfies(pkg.Name, pkg.Version, dep) {
|
||||
return true
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
rpc "github.com/Jguer/yay/v10/pkg/query"
|
||||
aur "github.com/Jguer/yay/v10/pkg/query"
|
||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||
"github.com/Jguer/yay/v10/pkg/text"
|
||||
)
|
||||
@ -41,7 +41,7 @@ func GetOrder(dp *Pool, noDeps, noCheckDeps bool) *Order {
|
||||
return do
|
||||
}
|
||||
|
||||
func (do *Order) orderPkgAur(pkg *rpc.Pkg, dp *Pool, runtime, noDeps, noCheckDeps bool) {
|
||||
func (do *Order) orderPkgAur(pkg *aur.Pkg, dp *Pool, runtime, noDeps, noCheckDeps bool) {
|
||||
if runtime {
|
||||
do.Runtime.Set(pkg.Name)
|
||||
}
|
||||
@ -117,7 +117,7 @@ func (do *Order) GetMake() []string {
|
||||
func (do *Order) Print() {
|
||||
repo := ""
|
||||
repoMake := ""
|
||||
aur := ""
|
||||
aurString := ""
|
||||
aurMake := ""
|
||||
|
||||
repoLen := 0
|
||||
@ -172,7 +172,7 @@ func (do *Order) Print() {
|
||||
}
|
||||
|
||||
if push {
|
||||
aur += pkgStr
|
||||
aurString += pkgStr
|
||||
}
|
||||
if pushMake {
|
||||
aurMake += pkgStrMake
|
||||
@ -181,7 +181,7 @@ func (do *Order) Print() {
|
||||
|
||||
printDownloads("Repo", repoLen, repo)
|
||||
printDownloads("Repo Make", repoMakeLen, repoMake)
|
||||
printDownloads("Aur", aurLen, aur)
|
||||
printDownloads("Aur", aurLen, aurString)
|
||||
printDownloads("Aur Make", aurMakeLen, aurMake)
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package dep
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
@ -9,8 +10,9 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/mikkeloscar/aur"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
"github.com/Jguer/yay/v10/pkg/query"
|
||||
@ -59,18 +61,20 @@ type Pool struct {
|
||||
Groups []string
|
||||
AlpmExecutor db.Executor
|
||||
Warnings *query.AURWarnings
|
||||
aurClient *aur.Client
|
||||
}
|
||||
|
||||
func makePool(dbExecutor db.Executor) *Pool {
|
||||
func makePool(dbExecutor db.Executor, aurClient *aur.Client) *Pool {
|
||||
dp := &Pool{
|
||||
make([]Target, 0),
|
||||
make(stringset.StringSet),
|
||||
make(map[string]db.IPackage),
|
||||
make(map[string]*query.Pkg),
|
||||
make(map[string]*query.Pkg),
|
||||
make([]string, 0),
|
||||
dbExecutor,
|
||||
nil,
|
||||
Targets: []Target{},
|
||||
Explicit: map[string]struct{}{},
|
||||
Repo: map[string]alpm.IPackage{},
|
||||
Aur: map[string]*aur.Pkg{},
|
||||
AurCache: map[string]*aur.Pkg{},
|
||||
Groups: []string{},
|
||||
AlpmExecutor: dbExecutor,
|
||||
Warnings: nil,
|
||||
aurClient: aurClient,
|
||||
}
|
||||
|
||||
return dp
|
||||
@ -81,8 +85,7 @@ func (dp *Pool) ResolveTargets(pkgs []string,
|
||||
mode settings.TargetMode,
|
||||
ignoreProviders, noConfirm, provides bool, rebuild string, splitN int, noDeps, noCheckDeps bool) error {
|
||||
// RPC requests are slow
|
||||
// Combine as many AUR package requests as possible into a single RPC
|
||||
// call
|
||||
// Combine as many AUR package requests as possible into a single RPC call
|
||||
aurTargets := make(stringset.StringSet)
|
||||
|
||||
pkgs = query.RemoveInvalidTargets(pkgs, mode)
|
||||
@ -182,7 +185,7 @@ func (dp *Pool) findProvides(pkgs stringset.StringSet) error {
|
||||
words := strings.Split(pkg, "-")
|
||||
|
||||
for i := range words {
|
||||
results, err = query.Search(strings.Join(words[:i+1], "-"))
|
||||
results, err = dp.aurClient.Search(context.Background(), strings.Join(words[:i+1], "-"), aur.None)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
@ -246,7 +249,7 @@ func (dp *Pool) cacheAURPackages(_pkgs stringset.StringSet, provides bool, split
|
||||
}
|
||||
}
|
||||
|
||||
info, err := query.AURInfo(toQuery, dp.Warnings, splitN)
|
||||
info, err := query.AURInfo(dp.aurClient, toQuery, dp.Warnings, splitN)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -370,10 +373,11 @@ func (dp *Pool) ResolveRepoDependency(pkg db.IPackage, noDeps bool) {
|
||||
func GetPool(pkgs []string,
|
||||
warnings *query.AURWarnings,
|
||||
dbExecutor db.Executor,
|
||||
aurClient *aur.Client,
|
||||
mode settings.TargetMode,
|
||||
ignoreProviders, noConfirm, provides bool,
|
||||
rebuild string, splitN int, noDeps bool, noCheckDeps bool) (*Pool, error) {
|
||||
dp := makePool(dbExecutor)
|
||||
dp := makePool(dbExecutor, aurClient)
|
||||
|
||||
dp.Warnings = warnings
|
||||
err := dp.ResolveTargets(pkgs, mode, ignoreProviders, noConfirm, provides, rebuild, splitN, noDeps, noCheckDeps)
|
||||
|
@ -13,9 +13,9 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
aur "github.com/Jguer/aur"
|
||||
gosrc "github.com/Morganamilo/go-srcinfo"
|
||||
"github.com/bradleyjkemp/cupaloy"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/dep"
|
||||
)
|
||||
@ -41,8 +41,8 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func newPkg(basename string) *rpc.Pkg {
|
||||
return &rpc.Pkg{Name: basename, PackageBase: basename}
|
||||
func newPkg(basename string) *aur.Pkg {
|
||||
return &aur.Pkg{Name: basename, PackageBase: basename}
|
||||
}
|
||||
|
||||
func getPgpKey(key string) string {
|
||||
|
@ -1,29 +1,25 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/intrange"
|
||||
"github.com/Jguer/yay/v10/pkg/multierror"
|
||||
"github.com/Jguer/yay/v10/pkg/text"
|
||||
)
|
||||
|
||||
type Pkg = rpc.Pkg
|
||||
|
||||
// Search is a reexport of rpc.Search
|
||||
func Search(query string) ([]Pkg, error) {
|
||||
return rpc.Search(query)
|
||||
}
|
||||
type Pkg = aur.Pkg
|
||||
|
||||
// Queries the aur for information about specified packages.
|
||||
// All packages should be queried in a single rpc request except when the number
|
||||
// All packages should be queried in a single aur request except when the number
|
||||
// of packages exceeds the number set in config.RequestSplitN.
|
||||
// If the number does exceed config.RequestSplitN multiple rpc requests will be
|
||||
// If the number does exceed config.RequestSplitN multiple aur requests will be
|
||||
// performed concurrently.
|
||||
func AURInfo(names []string, warnings *AURWarnings, splitN int) ([]*Pkg, error) {
|
||||
func AURInfo(aurClient *aur.Client, names []string, warnings *AURWarnings, splitN int) ([]*Pkg, error) {
|
||||
info := make([]*Pkg, 0, len(names))
|
||||
seen := make(map[string]int)
|
||||
var mux sync.Mutex
|
||||
@ -32,7 +28,7 @@ func AURInfo(names []string, warnings *AURWarnings, splitN int) ([]*Pkg, error)
|
||||
|
||||
makeRequest := func(n, max int) {
|
||||
defer wg.Done()
|
||||
tempInfo, requestErr := rpc.Info(names[n:max])
|
||||
tempInfo, requestErr := aurClient.Info(context.Background(), names[n:max])
|
||||
errs.Add(requestErr)
|
||||
if requestErr != nil {
|
||||
return
|
||||
@ -80,11 +76,11 @@ func AURInfo(names []string, warnings *AURWarnings, splitN int) ([]*Pkg, error)
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func AURInfoPrint(names []string, splitN int) ([]*Pkg, error) {
|
||||
func AURInfoPrint(aurClient *aur.Client, names []string, splitN int) ([]*Pkg, error) {
|
||||
text.OperationInfoln(gotext.Get("Querying AUR..."))
|
||||
|
||||
warnings := &AURWarnings{}
|
||||
info, err := AURInfo(names, warnings, splitN)
|
||||
info, err := AURInfo(aurClient, names, warnings, splitN)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package settings
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@ -11,6 +12,8 @@ import (
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v10/pkg/vcs"
|
||||
)
|
||||
@ -184,7 +187,7 @@ func DefaultConfig() *Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
func NewConfig() (*Configuration, error) {
|
||||
func NewConfig(version string) (*Configuration, error) {
|
||||
newConfig := DefaultConfig()
|
||||
|
||||
cacheHome := getCacheHome()
|
||||
@ -215,6 +218,20 @@ func NewConfig() (*Configuration, error) {
|
||||
PacmanConf: nil,
|
||||
VCSStore: nil,
|
||||
HTTPClient: &http.Client{},
|
||||
AURClient: nil,
|
||||
}
|
||||
|
||||
var errAUR error
|
||||
|
||||
newConfig.Runtime.AURClient, errAUR = aur.NewClient(aur.WithHTTPClient(newConfig.Runtime.HTTPClient),
|
||||
aur.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
|
||||
req.Header.Set("User-Agent", fmt.Sprintf("Yay/%s", version))
|
||||
|
||||
return nil
|
||||
}))
|
||||
|
||||
if errAUR != nil {
|
||||
return nil, errAUR
|
||||
}
|
||||
|
||||
newConfig.Runtime.VCSStore = vcs.NewInfoStore(filepath.Join(cacheHome, vcsFileName),
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/leonelquinteros/gotext"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -836,6 +835,6 @@ func (a *Arguments) extractYayOptions(config *Configuration) {
|
||||
}
|
||||
}
|
||||
|
||||
rpc.AURURL = strings.TrimRight(config.AURURL, "/") + "/rpc.php?"
|
||||
config.Runtime.AURClient.BaseURL = strings.TrimRight(config.AURURL, "/") + "/aur.php?"
|
||||
config.AURURL = strings.TrimRight(config.AURURL, "/")
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
|
||||
"github.com/Morganamilo/go-pacmanconf"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v10/pkg/vcs"
|
||||
)
|
||||
@ -27,4 +29,5 @@ type Runtime struct {
|
||||
CmdBuilder *exe.CmdBuilder
|
||||
CmdRunner exe.Runner
|
||||
HTTPClient *http.Client
|
||||
AURClient *aur.Client
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
aur "github.com/Jguer/aur"
|
||||
"github.com/bradleyjkemp/cupaloy"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
@ -23,7 +23,7 @@ import (
|
||||
func Test_upAUR(t *testing.T) {
|
||||
type args struct {
|
||||
remote []alpm.IPackage
|
||||
aurdata map[string]*rpc.Pkg
|
||||
aurdata map[string]*aur.Pkg
|
||||
timeUpdate bool
|
||||
}
|
||||
tests := []struct {
|
||||
@ -39,7 +39,7 @@ func Test_upAUR(t *testing.T) {
|
||||
&mock.Package{PName: "local_pkg", PVersion: "1.1.0"},
|
||||
&mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
|
||||
},
|
||||
aurdata: map[string]*rpc.Pkg{
|
||||
aurdata: map[string]*aur.Pkg{
|
||||
"hello": {Version: "2.0.0", Name: "hello"},
|
||||
"ignored": {Version: "2.0.0", Name: "ignored"},
|
||||
},
|
||||
@ -51,7 +51,7 @@ func Test_upAUR(t *testing.T) {
|
||||
name: "Simple Update",
|
||||
args: args{
|
||||
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0"}},
|
||||
aurdata: map[string]*rpc.Pkg{"hello": {Version: "2.1.0", Name: "hello"}},
|
||||
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.1.0", Name: "hello"}},
|
||||
timeUpdate: false,
|
||||
},
|
||||
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.1.0"}}},
|
||||
@ -60,7 +60,7 @@ func Test_upAUR(t *testing.T) {
|
||||
name: "Time Update",
|
||||
args: args{
|
||||
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0", PBuildDate: time.Now()}},
|
||||
aurdata: map[string]*rpc.Pkg{"hello": {Version: "2.0.0", Name: "hello", LastModified: int(time.Now().AddDate(0, 0, 2).Unix())}},
|
||||
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello", LastModified: int(time.Now().AddDate(0, 0, 2).Unix())}},
|
||||
timeUpdate: true,
|
||||
},
|
||||
want: UpSlice{Repos: []string{"aur"}, Up: []Upgrade{{Name: "hello", Repository: "aur", LocalVersion: "2.0.0", RemoteVersion: "2.0.0"}}},
|
||||
@ -106,7 +106,7 @@ func (r *MockRunner) Capture(cmd *exec.Cmd, timeout int64) (stdout, stderr strin
|
||||
|
||||
func Test_upDevel(t *testing.T) {
|
||||
var err error
|
||||
config, err := settings.NewConfig()
|
||||
config, err := settings.NewConfig("v0")
|
||||
assert.NoError(t, err)
|
||||
|
||||
config.Runtime.CmdRunner = &MockRunner{
|
||||
@ -121,7 +121,7 @@ func Test_upDevel(t *testing.T) {
|
||||
|
||||
type args struct {
|
||||
remote []alpm.IPackage
|
||||
aurdata map[string]*rpc.Pkg
|
||||
aurdata map[string]*aur.Pkg
|
||||
cached vcs.InfoStore
|
||||
}
|
||||
tests := []struct {
|
||||
@ -142,7 +142,7 @@ func Test_upDevel(t *testing.T) {
|
||||
&mock.Package{PName: "local_pkg", PVersion: "1.1.0"},
|
||||
&mock.Package{PName: "ignored", PVersion: "1.0.0", PShouldIgnore: true},
|
||||
},
|
||||
aurdata: map[string]*rpc.Pkg{
|
||||
aurdata: map[string]*aur.Pkg{
|
||||
"hello": {Version: "2.0.0", Name: "hello"},
|
||||
"ignored": {Version: "2.0.0", Name: "ignored"},
|
||||
},
|
||||
@ -197,7 +197,7 @@ func Test_upDevel(t *testing.T) {
|
||||
&mock.Package{PName: "hello2", PVersion: "3.0.0"},
|
||||
&mock.Package{PName: "hello4", PVersion: "4.0.0"},
|
||||
},
|
||||
aurdata: map[string]*rpc.Pkg{
|
||||
aurdata: map[string]*aur.Pkg{
|
||||
"hello": {Version: "2.0.0", Name: "hello"},
|
||||
"hello2": {Version: "2.0.0", Name: "hello2"},
|
||||
"hello4": {Version: "2.0.0", Name: "hello4"},
|
||||
@ -235,7 +235,7 @@ func Test_upDevel(t *testing.T) {
|
||||
},
|
||||
},
|
||||
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0"}},
|
||||
aurdata: map[string]*rpc.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
|
||||
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
|
||||
},
|
||||
want: UpSlice{Repos: []string{"devel"}},
|
||||
},
|
||||
@ -257,7 +257,7 @@ func Test_upDevel(t *testing.T) {
|
||||
},
|
||||
},
|
||||
remote: []alpm.IPackage{&mock.Package{PName: "hello", PVersion: "2.0.0", PShouldIgnore: true}},
|
||||
aurdata: map[string]*rpc.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
|
||||
aurdata: map[string]*aur.Pkg{"hello": {Version: "2.0.0", Name: "hello"}},
|
||||
},
|
||||
want: UpSlice{Repos: []string{"devel"}},
|
||||
},
|
||||
|
6
print.go
6
print.go
@ -7,8 +7,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
aur "github.com/Jguer/aur"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
"github.com/Jguer/yay/v10/pkg/download"
|
||||
@ -106,7 +106,7 @@ func (s repoQuery) printSearch(dbExecutor db.Executor) {
|
||||
// Pretty print a set of packages from the same package base.
|
||||
|
||||
// PrintInfo prints package info like pacman -Si.
|
||||
func PrintInfo(a *rpc.Pkg, extendedInfo bool) {
|
||||
func PrintInfo(a *aur.Pkg, extendedInfo bool) {
|
||||
text.PrintInfoValue(gotext.Get("Repository"), "aur")
|
||||
text.PrintInfoValue(gotext.Get("Name"), a.Name)
|
||||
text.PrintInfoValue(gotext.Get("Keywords"), a.Keywords...)
|
||||
@ -178,7 +178,7 @@ func localStatistics(dbExecutor db.Executor) error {
|
||||
biggestPackages(dbExecutor)
|
||||
fmt.Println(text.Bold(text.Cyan("===========================================")))
|
||||
|
||||
query.AURInfoPrint(remoteNames, config.RequestSplitN)
|
||||
query.AURInfoPrint(config.Runtime.AURClient, remoteNames, config.RequestSplitN)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
47
query.go
47
query.go
@ -1,15 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
aur "github.com/Jguer/aur"
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
"github.com/Jguer/yay/v10/pkg/query"
|
||||
@ -19,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
// Query is a collection of Results
|
||||
type aurQuery []rpc.Pkg
|
||||
type aurQuery []aur.Pkg
|
||||
|
||||
// Query holds the results of a repository search.
|
||||
type repoQuery []alpm.IPackage
|
||||
@ -67,28 +68,28 @@ func (q aurQuery) Swap(i, j int) {
|
||||
q[i], q[j] = q[j], q[i]
|
||||
}
|
||||
|
||||
func getSearchBy(value string) rpc.By {
|
||||
func getSearchBy(value string) aur.By {
|
||||
switch value {
|
||||
case "name":
|
||||
return rpc.Name
|
||||
return aur.Name
|
||||
case "maintainer":
|
||||
return rpc.Maintainer
|
||||
return aur.Maintainer
|
||||
case "depends":
|
||||
return rpc.Depends
|
||||
return aur.Depends
|
||||
case "makedepends":
|
||||
return rpc.MakeDepends
|
||||
return aur.MakeDepends
|
||||
case "optdepends":
|
||||
return rpc.OptDepends
|
||||
return aur.OptDepends
|
||||
case "checkdepends":
|
||||
return rpc.CheckDepends
|
||||
return aur.CheckDepends
|
||||
default:
|
||||
return rpc.NameDesc
|
||||
return aur.NameDesc
|
||||
}
|
||||
}
|
||||
|
||||
// NarrowSearch searches AUR and narrows based on subarguments
|
||||
func narrowSearch(pkgS []string, sortS bool) (aurQuery, error) {
|
||||
var r []rpc.Pkg
|
||||
func narrowSearch(aurClient *aur.Client, pkgS []string, sortS bool) (aurQuery, error) {
|
||||
var r []aur.Pkg
|
||||
var err error
|
||||
var usedIndex int
|
||||
|
||||
@ -99,7 +100,7 @@ func narrowSearch(pkgS []string, sortS bool) (aurQuery, error) {
|
||||
}
|
||||
|
||||
for i, word := range pkgS {
|
||||
r, err = rpc.SearchBy(word, by)
|
||||
r, err = aurClient.Search(context.Background(), word, by)
|
||||
if err == nil {
|
||||
usedIndex = i
|
||||
break
|
||||
@ -147,14 +148,14 @@ func narrowSearch(pkgS []string, sortS bool) (aurQuery, error) {
|
||||
}
|
||||
|
||||
// SyncSearch presents a query to the local repos and to the AUR.
|
||||
func syncSearch(pkgS []string, dbExecutor db.Executor) (err error) {
|
||||
func syncSearch(pkgS []string, aurClient *aur.Client, dbExecutor db.Executor) (err error) {
|
||||
pkgS = query.RemoveInvalidTargets(pkgS, config.Runtime.Mode)
|
||||
var aurErr error
|
||||
var aq aurQuery
|
||||
var pq repoQuery
|
||||
|
||||
if config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny {
|
||||
aq, aurErr = narrowSearch(pkgS, true)
|
||||
aq, aurErr = narrowSearch(aurClient, pkgS, true)
|
||||
}
|
||||
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
|
||||
pq = queryRepo(pkgS, dbExecutor)
|
||||
@ -189,7 +190,7 @@ func syncSearch(pkgS []string, dbExecutor db.Executor) (err error) {
|
||||
|
||||
// SyncInfo serves as a pacman -Si for repo packages and AUR packages.
|
||||
func syncInfo(cmdArgs *settings.Arguments, pkgS []string, dbExecutor db.Executor) error {
|
||||
var info []*rpc.Pkg
|
||||
var info []*aur.Pkg
|
||||
var err error
|
||||
missing := false
|
||||
pkgS = query.RemoveInvalidTargets(pkgS, config.Runtime.Mode)
|
||||
@ -203,7 +204,7 @@ func syncInfo(cmdArgs *settings.Arguments, pkgS []string, dbExecutor db.Executor
|
||||
noDB = append(noDB, name)
|
||||
}
|
||||
|
||||
info, err = query.AURInfoPrint(noDB, config.RequestSplitN)
|
||||
info, err = query.AURInfoPrint(config.Runtime.AURClient, noDB, config.RequestSplitN)
|
||||
if err != nil {
|
||||
missing = true
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
@ -250,27 +251,27 @@ func queryRepo(pkgInputN []string, dbExecutor db.Executor) repoQuery {
|
||||
}
|
||||
|
||||
// PackageSlices separates an input slice into aur and repo slices
|
||||
func packageSlices(toCheck []string, dbExecutor db.Executor) (aur, repo []string) {
|
||||
func packageSlices(toCheck []string, dbExecutor db.Executor) (aurNames, repoNames []string) {
|
||||
for _, _pkg := range toCheck {
|
||||
dbName, name := text.SplitDBFromName(_pkg)
|
||||
|
||||
if dbName == "aur" || config.Runtime.Mode == settings.ModeAUR {
|
||||
aur = append(aur, _pkg)
|
||||
aurNames = append(aurNames, _pkg)
|
||||
continue
|
||||
} else if dbName != "" || config.Runtime.Mode == settings.ModeRepo {
|
||||
repo = append(repo, _pkg)
|
||||
repoNames = append(repoNames, _pkg)
|
||||
continue
|
||||
}
|
||||
|
||||
if dbExecutor.SyncSatisfierExists(name) ||
|
||||
len(dbExecutor.PackagesFromGroup(name)) != 0 {
|
||||
repo = append(repo, _pkg)
|
||||
repoNames = append(repoNames, _pkg)
|
||||
} else {
|
||||
aur = append(aur, _pkg)
|
||||
aurNames = append(aurNames, _pkg)
|
||||
}
|
||||
}
|
||||
|
||||
return aur, repo
|
||||
return aurNames, repoNames
|
||||
}
|
||||
|
||||
// HangingPackages returns a list of packages installed as deps
|
||||
|
10
upgrade.go
10
upgrade.go
@ -6,9 +6,9 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
aur "github.com/Jguer/aur"
|
||||
alpm "github.com/Jguer/go-alpm/v2"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
rpc "github.com/mikkeloscar/aur"
|
||||
|
||||
"github.com/Jguer/yay/v10/pkg/db"
|
||||
"github.com/Jguer/yay/v10/pkg/intrange"
|
||||
@ -40,7 +40,7 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
||||
var repoSlice []db.Upgrade
|
||||
var errs multierror.MultiError
|
||||
|
||||
aurdata := make(map[string]*rpc.Pkg)
|
||||
aurdata := make(map[string]*aur.Pkg)
|
||||
|
||||
for _, pkg := range remote {
|
||||
if pkg.ShouldIgnore() {
|
||||
@ -61,8 +61,8 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
||||
if config.Runtime.Mode == settings.ModeAny || config.Runtime.Mode == settings.ModeAUR {
|
||||
text.OperationInfoln(gotext.Get("Searching AUR for updates..."))
|
||||
|
||||
var _aurdata []*rpc.Pkg
|
||||
_aurdata, err = query.AURInfo(remoteNames, warnings, config.RequestSplitN)
|
||||
var _aurdata []*aur.Pkg
|
||||
_aurdata, err = query.AURInfo(config.Runtime.AURClient, remoteNames, warnings, config.RequestSplitN)
|
||||
errs.Add(err)
|
||||
if err == nil {
|
||||
for _, pkg := range _aurdata {
|
||||
@ -109,7 +109,7 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
||||
}
|
||||
|
||||
func printLocalNewerThanAUR(
|
||||
remote []alpm.IPackage, aurdata map[string]*rpc.Pkg) {
|
||||
remote []alpm.IPackage, aurdata map[string]*aur.Pkg) {
|
||||
for _, pkg := range remote {
|
||||
aurPkg, ok := aurdata[pkg.Name()]
|
||||
if !ok {
|
||||
|
2
vcs.go
2
vcs.go
@ -23,7 +23,7 @@ func createDevelDB(config *settings.Configuration, dbExecutor db.Executor) error
|
||||
return err
|
||||
}
|
||||
|
||||
info, err := query.AURInfoPrint(remoteNames, config.RequestSplitN)
|
||||
info, err := query.AURInfoPrint(config.Runtime.AURClient, remoteNames, config.RequestSplitN)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user