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

Add fuzzy name matching and mixed sources #1719

Merged
merged 11 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ linters:
- whitespace
- wsl
- godot
# - maligned
# - interfacer
# - nilerr
# - nlreturn
# - exhaustivestruct
# - errname
# - forbidigo

run:

Expand Down
18 changes: 7 additions & 11 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func handleCmd(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Exe
case "P", "show":
return handlePrint(ctx, cmdArgs, dbExecutor)
case "Y", "--yay":
return handleYay(ctx, cmdArgs, dbExecutor)
return handleYay(ctx, cmdArgs, dbExecutor, config.Runtime.QueryBuilder)
}

return errors.New(gotext.Get("unhandled operation"))
Expand Down Expand Up @@ -289,7 +289,7 @@ func handlePrint(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.E
return nil
}

func handleYay(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
func handleYay(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Executor, queryBuilder query.Builder) error {
switch {
case cmdArgs.ExistsArg("gendb"):
return createDevelDB(ctx, config, dbExecutor)
Expand All @@ -298,7 +298,7 @@ func handleYay(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Exe
case cmdArgs.ExistsArg("c", "clean"):
return cleanDependencies(ctx, cmdArgs, dbExecutor, false)
case len(cmdArgs.Targets) > 0:
return handleYogurt(ctx, cmdArgs, dbExecutor)
return displayNumberMenu(ctx, cmdArgs.Targets, dbExecutor, queryBuilder, cmdArgs)
}

return nil
Expand All @@ -312,16 +312,12 @@ func handleGetpkgbuild(ctx context.Context, cmdArgs *parser.Arguments, dbExecuto
return getPkgbuilds(ctx, dbExecutor, config, cmdArgs.Targets, cmdArgs.ExistsArg("f", "force"))
}

func handleYogurt(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
return displayNumberMenu(ctx, cmdArgs.Targets, dbExecutor, cmdArgs)
}

func handleSync(ctx context.Context, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
targets := cmdArgs.Targets

switch {
case cmdArgs.ExistsArg("s", "search"):
return syncSearch(ctx, targets, config.Runtime.AURClient, dbExecutor, !cmdArgs.ExistsArg("q", "quiet"))
return syncSearch(ctx, targets, config.Runtime.AURClient, dbExecutor, config.Runtime.QueryBuilder, !cmdArgs.ExistsArg("q", "quiet"))
case cmdArgs.ExistsArg("p", "print", "print-format"):
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(ctx,
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
Expand Down Expand Up @@ -355,9 +351,9 @@ func handleRemove(ctx context.Context, cmdArgs *parser.Arguments, localCache *vc
}

// NumberMenu presents a CLI for selecting packages to install.
func displayNumberMenu(ctx context.Context, pkgS []string, dbExecutor db.Executor, cmdArgs *parser.Arguments) error {
queryBuilder := query.NewSourceQueryBuilder(config.SortBy, config.Runtime.Mode, config.SearchBy, config.BottomUp, config.SingleLineResults)

func displayNumberMenu(ctx context.Context, pkgS []string, dbExecutor db.Executor,
queryBuilder query.Builder, cmdArgs *parser.Arguments,
) error {
queryBuilder.Execute(ctx, dbExecutor, config.Runtime.AURClient, pkgS)

if err := queryBuilder.Results(os.Stdout, dbExecutor, query.NumberMenu); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions doc/yay.8
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ the last modification time of each package's AUR page.
.B \-\-notimeupdate
Do not consider build times during sysupgrade.

.TP
.B \-\-separatesources
Separate query results by source, AUR and sync

.TP
.B \-\-noseparatesources
Do not separate query results by source for searching

.TP
.B \-\-redownload
Always download pkgbuilds of targets even when a copy is available in cache.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
)

require (
github.com/adrg/strutil v0.2.3
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5 h1:TMscP
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5/go.mod h1:Hk55m330jNiwxRodIlMCvw5iEyoRUCIY64W1p9D+tHc=
github.com/Morganamilo/go-srcinfo v1.0.0 h1:Wh4nEF+HJWo+29hnxM18Q2hi+DUf0GejS13+Wg+dzmI=
github.com/Morganamilo/go-srcinfo v1.0.0/go.mod h1:MP6VGY1NNpVUmYIEgoM9acix95KQqIRyqQ0hCLsyYUY=
github.com/adrg/strutil v0.2.3 h1:WZVn3ItPBovFmP4wMHHVXUr8luRaHrbyIuLlHt32GZQ=
github.com/adrg/strutil v0.2.3/go.mod h1:+SNxbiH6t+O+5SZqIj5n/9i5yUjR+S3XXVrjEcN2mxg=
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible h1:UafIjBvWQmS9i/xRg+CamMrnLTKNzo+bdmT/oH34c2Y=
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible/go.mod h1:Au1Xw1sgaJ5iSFktEhYsS0dbQiS1B0/XMXl+42y9Ilk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/db/ialpm"
"github.com/Jguer/yay/v11/pkg/query"
"github.com/Jguer/yay/v11/pkg/settings"
"github.com/Jguer/yay/v11/pkg/settings/parser"
"github.com/Jguer/yay/v11/pkg/text"
Expand Down Expand Up @@ -131,6 +132,14 @@ func main() {
}
}

if config.SeparateSources {
config.Runtime.QueryBuilder = query.NewSourceQueryBuilder(config.SortBy,
config.Runtime.Mode, config.SearchBy, config.BottomUp, config.SingleLineResults)
} else {
config.Runtime.QueryBuilder = query.NewMixedSourceQueryBuilder(config.SortBy,
config.Runtime.Mode, config.SearchBy, config.BottomUp, config.SingleLineResults)
}

var useColor bool

config.Runtime.PacmanConf, useColor, err = initAlpm(cmdArgs, config.PacmanConf)
Expand Down
5 changes: 3 additions & 2 deletions pkg/db/ialpm/alpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (ae *AlpmExecutor) questionCallback() func(question alpm.QuestionAny) {
return nil
})

str := text.Bold(gotext.Get("There are %d providers available for %s:\n", size, qp.Dep()))
str := text.Bold(gotext.Get("There are %d providers available for %s:", size, qp.Dep()))

size = 1

Expand All @@ -171,7 +171,8 @@ func (ae *AlpmExecutor) questionCallback() func(question alpm.QuestionAny) {

if dbName != thisDB {
dbName = thisDB
str += text.SprintOperationInfo(gotext.Get("Repository"), dbName, "\n ")
str += "\n"
str += text.SprintOperationInfo(gotext.Get("Repository"), " ", dbName, "\n ")
}
str += fmt.Sprintf("%d) %s ", size, pkg.Name())
size++
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/mock/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (p *Package) Packager() string {

// Provides returns DependList of packages provides by package.
func (p *Package) Provides() alpm.DependList {
panic("not implemented") // TODO: Implement
return alpm.DependList{}
}

// Origin returns package origin.
Expand Down
Loading