mirror of
https://github.com/Jguer/yay.git
synced 2025-12-27 10:01:53 -05:00
fix(new_engine): add aur client support to mixed source display (#1919)
* update aur client and use correct aur client * add aur query client support for mixed source engine
This commit is contained in:
6
go.mod
6
go.mod
@@ -1,7 +1,7 @@
|
||||
module github.com/Jguer/yay/v11
|
||||
|
||||
require (
|
||||
github.com/Jguer/aur v1.2.0
|
||||
github.com/Jguer/aur v1.2.1
|
||||
github.com/Jguer/go-alpm/v2 v2.1.2
|
||||
github.com/Jguer/votar v1.0.0
|
||||
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5
|
||||
@@ -31,9 +31,11 @@ require (
|
||||
github.com/ohler55/ojg v1.17.5 // indirect
|
||||
)
|
||||
|
||||
require github.com/hashicorp/go-multierror v1.1.1
|
||||
|
||||
require (
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
)
|
||||
|
||||
go 1.19
|
||||
|
||||
6
go.sum
6
go.sum
@@ -1,5 +1,5 @@
|
||||
github.com/Jguer/aur v1.2.0 h1:hWg0JcGQ9WkPlnElr3tZ6dW+GfD/wZTr9kym5GFY3OE=
|
||||
github.com/Jguer/aur v1.2.0/go.mod h1:x4iPZX1qZoQtPiYgFepVO/6kbz7zwFkep8gz5tzga64=
|
||||
github.com/Jguer/aur v1.2.1 h1:7ViPn4EN10iMAhtUSugxytloCynyVI12HzfhnGG1xGE=
|
||||
github.com/Jguer/aur v1.2.1/go.mod h1:Dahvb6L1yr0rR7svyYSDwaRJoQMeyvJblwJ3QH/7CUs=
|
||||
github.com/Jguer/go-alpm/v2 v2.1.2 h1:CGTIxzuEpT9Q3a7IBrx0E6acoYoaHX2Z93UOApPDhgU=
|
||||
github.com/Jguer/go-alpm/v2 v2.1.2/go.mod h1:uLQcTMNM904dRiGU+/JDtDdd7Nd8mVbEVaHjhmziT7w=
|
||||
github.com/Jguer/votar v1.0.0 h1:drPYpV5Py5BeAQS8xezmT6uCEfLzotNjLf5yfmlHKTg=
|
||||
@@ -32,6 +32,8 @@ github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm
|
||||
github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8=
|
||||
github.com/leonelquinteros/gotext v1.5.1 h1:vmddRn3gHp67YFjZLZE2AZsgYMT4IBTJhua4yfe7/4Q=
|
||||
github.com/leonelquinteros/gotext v1.5.1/go.mod h1:/A4Y7BvIsf5JHO60E43ZQDVkV3qO+7eP8HjeqD6ChIA=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
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/ohler55/ojg v1.17.5 h1:SY6/cdhVzsLinNFIBRNSWhJgihvEWco5Y0TJe46XJ1Y=
|
||||
|
||||
5
main.go
5
main.go
@@ -101,8 +101,9 @@ func main() {
|
||||
config.SingleLineResults, config.NewInstallEngine)
|
||||
} else {
|
||||
config.Runtime.QueryBuilder = query.NewMixedSourceQueryBuilder(
|
||||
config.Runtime.AURClient, config.SortBy,
|
||||
config.Runtime.Mode, config.SearchBy, config.BottomUp, config.SingleLineResults)
|
||||
config.Runtime.AURClient, config.Runtime.AURCache, config.SortBy,
|
||||
config.Runtime.Mode, config.SearchBy,
|
||||
config.BottomUp, config.SingleLineResults, config.NewInstallEngine)
|
||||
}
|
||||
|
||||
var useColor bool
|
||||
|
||||
@@ -39,19 +39,24 @@ type MixedSourceQueryBuilder struct {
|
||||
queryMap map[string]map[string]interface{}
|
||||
bottomUp bool
|
||||
singleLineResults bool
|
||||
newEngine bool
|
||||
|
||||
aurClient rpc.ClientInterface
|
||||
aurClient aur.QueryClient
|
||||
rpcClient rpc.ClientInterface
|
||||
}
|
||||
|
||||
func NewMixedSourceQueryBuilder(
|
||||
aurClient rpc.ClientInterface,
|
||||
rpcClient rpc.ClientInterface,
|
||||
aurClient aur.QueryClient,
|
||||
sortBy string,
|
||||
targetMode parser.TargetMode,
|
||||
searchBy string,
|
||||
bottomUp,
|
||||
singleLineResults bool,
|
||||
newEngine bool,
|
||||
) *MixedSourceQueryBuilder {
|
||||
return &MixedSourceQueryBuilder{
|
||||
rpcClient: rpcClient,
|
||||
aurClient: aurClient,
|
||||
bottomUp: bottomUp,
|
||||
sortBy: sortBy,
|
||||
@@ -60,6 +65,7 @@ func NewMixedSourceQueryBuilder(
|
||||
singleLineResults: singleLineResults,
|
||||
queryMap: map[string]map[string]interface{}{},
|
||||
results: make([]abstractResult, 0, 100),
|
||||
newEngine: newEngine,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +152,7 @@ func (s *MixedSourceQueryBuilder) Execute(ctx context.Context, dbExecutor db.Exe
|
||||
|
||||
if s.targetMode.AtLeastAUR() {
|
||||
var aurResults aurQuery
|
||||
aurResults, aurErr = queryAUR(ctx, s.aurClient, nil, pkgS, s.searchBy, false)
|
||||
aurResults, aurErr = queryAUR(ctx, s.rpcClient, s.aurClient, pkgS, s.searchBy, false)
|
||||
dbName := sourceAUR
|
||||
|
||||
for i := range aurResults {
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestMixedSourceQueryBuilder(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
client, err := rpc.NewClient(rpc.WithHTTPClient(&mockDoer{}))
|
||||
queryBuilder := NewMixedSourceQueryBuilder(client, "votes", parser.ModeAny, "", tc.bottomUp, false)
|
||||
queryBuilder := NewMixedSourceQueryBuilder(client, client, "votes", parser.ModeAny, "", tc.bottomUp, false, false)
|
||||
search := []string{"linux"}
|
||||
mockStore := &mockDB{}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
"github.com/Jguer/go-alpm/v2"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
|
||||
"github.com/Jguer/yay/v11/pkg/db"
|
||||
@@ -193,7 +194,7 @@ func filterAURResults(pkgS []string, results []aur.Pkg) []aur.Pkg {
|
||||
|
||||
// queryAUR searches AUR and narrows based on subarguments.
|
||||
func queryAUR(ctx context.Context,
|
||||
aurClient rpc.ClientInterface, aurMetadata aur.QueryClient,
|
||||
rpcClient rpc.ClientInterface, aurClient aur.QueryClient,
|
||||
pkgS []string, searchBy string, newEngine bool,
|
||||
) ([]aur.Pkg, error) {
|
||||
var (
|
||||
@@ -201,32 +202,22 @@ func queryAUR(ctx context.Context,
|
||||
by = getSearchBy(searchBy)
|
||||
)
|
||||
|
||||
queryClient := aurClient
|
||||
if !newEngine {
|
||||
queryClient = rpcClient
|
||||
}
|
||||
|
||||
for _, word := range pkgS {
|
||||
var r []aur.Pkg
|
||||
|
||||
if aurMetadata != nil && newEngine {
|
||||
q, errM := aurMetadata.Get(ctx, &aur.Query{
|
||||
Needles: []string{word},
|
||||
By: by,
|
||||
Contains: true,
|
||||
})
|
||||
|
||||
r = append(r, q...)
|
||||
|
||||
if errM == nil {
|
||||
return r, nil
|
||||
}
|
||||
|
||||
text.Warnln("AUR Metadata search failed:", err)
|
||||
r, errM := queryClient.Get(ctx, &aur.Query{
|
||||
Needles: []string{word},
|
||||
By: by,
|
||||
Contains: true,
|
||||
})
|
||||
if errM == nil {
|
||||
return r, nil
|
||||
}
|
||||
// if one of the search terms returns a result we start filtering by it
|
||||
if aurClient != nil {
|
||||
text.Debugln("AUR RPC:", by, word)
|
||||
|
||||
if r, err = aurClient.Search(ctx, word, by); err == nil {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
err = multierror.Append(err, errM)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user