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 the option to display package URLs in the search results #2330

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestYogurtMenuAURDB(t *testing.T) {
CmdBuilder: cmdBuilder,
VCSStore: &vcs.Mock{},
QueryBuilder: query.NewSourceQueryBuilder(aurCache, logger, "votes", parser.ModeAny, "name",
true, false, true),
true, false, true, false),
AURClient: aurCache,
}
err = handleCmd(context.Background(), run, cmdArgs, db)
Expand Down
2 changes: 1 addition & 1 deletion completions/bash
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ _yay() {
noconfirm noprogressbar noscriptlet quiet root verbose
makepkg pacman git gpg gpgflags config requestsplitn sudoloop
redownload noredownload redownloadall rebuild rebuildall rebuildtree norebuild sortby
singlelineresults doublelineresults answerclean answerdiff answeredit answerupgrade noanswerclean noanswerdiff
singlelineresults doublelineresults showpackageurls answerclean answerdiff answeredit answerupgrade noanswerclean noanswerdiff
noansweredit noanswerupgrade cleanmenu diffmenu editmenu cleanafter keepsrc
provides pgpfetch
useask combinedupgrade aur repo makepkgconf
Expand Down
1 change: 1 addition & 0 deletions completions/fish
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ complete -c $progname -n "not $noopt" -l topdown -d 'Shows repository packages f
complete -c $progname -n "not $noopt" -l bottomup -d 'Shows aur packages first and then repository' -f
complete -c $progname -n "not $noopt" -l singlelineresults -d 'List each search result on its own line' -f
complete -c $progname -n "not $noopt" -l doublelineresults -d 'List each search result on two lines, like pacman' -f
complete -c $progname -n "not $noopt" -l showpackageurls -d 'Show the URL of each package in the search results' -f
complete -c $progname -n "not $noopt" -l devel -d 'Check -git/-svn/-hg development version' -f
complete -c $progname -n "not $noopt" -l cleanafter -d 'Clean package sources after successful build' -f
complete -c $progname -n "not $noopt" -l keepsrc -d 'Keep pkg/ and src/ after building packages' -f
Expand Down
1 change: 1 addition & 0 deletions completions/zsh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ _pacman_opts_common=(
'--topdown[Show repository packages first]'
'--singlelineresults[List each search result on its own line]'
'--doublelineresults[List each search result on two lines, like pacman]'
'--showpackageurls[Show the URL of each package in the search results]'
'--devel[Check -git/-svn/-hg development version]'
'--cleanafter[Clean package sources after successful build]'
'--keepsrc[Keep pkg/ and src/ after building packages]'
Expand Down
4 changes: 4 additions & 0 deletions doc/yay.8
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ on its own line.
Follow pacman's double-line search result format and list each result using
two lines.

.TP
.B \-\-showpackageurls
Show the URL of each package in the search results.

.TP
.B \-\-devel
During sysupgrade also check AUR development packages for updates. Currently
Expand Down
3 changes: 2 additions & 1 deletion pkg/db/mock/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (d DependList) ForEach(f func(*alpm.Depend) error) error {
}

type Package struct {
PArchitecture string
PBase string
PBuildDate time.Time
PDB *DB
Expand Down Expand Up @@ -95,7 +96,7 @@ func (p *Package) Validation() alpm.Validation {

// Architecture returns the package target Architecture.
func (p *Package) Architecture() string {
panic("not implemented")
return p.PArchitecture
}

// Backup returns a list of package backups.
Expand Down
7 changes: 5 additions & 2 deletions pkg/query/query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type SourceQueryBuilder struct {
bottomUp bool
singleLineResults bool
separateSources bool
showPackageURLs bool

aurClient aur.QueryClient
logger *text.Logger
Expand All @@ -61,6 +62,7 @@ func NewSourceQueryBuilder(
bottomUp,
singleLineResults bool,
separateSources bool,
showPackageURLs bool,
) *SourceQueryBuilder {
return &SourceQueryBuilder{
aurClient: aurClient,
Expand All @@ -71,6 +73,7 @@ func NewSourceQueryBuilder(
searchBy: searchBy,
singleLineResults: singleLineResults,
separateSources: separateSources,
showPackageURLs: showPackageURLs,
queryMap: map[string]map[string]interface{}{},
results: make([]abstractResult, 0, 100),
}
Expand Down Expand Up @@ -237,9 +240,9 @@ func (s *SourceQueryBuilder) Results(dbExecutor db.Executor, verboseSearch Searc

switch pPkg := pkg.(type) {
case aur.Pkg:
toPrint += aurPkgSearchString(&pPkg, dbExecutor, s.singleLineResults)
toPrint += aurPkgSearchString(&pPkg, dbExecutor, s.singleLineResults, s.showPackageURLs)
case alpm.IPackage:
toPrint += syncPkgSearchString(pPkg, dbExecutor, s.singleLineResults)
toPrint += syncPkgSearchString(pPkg, dbExecutor, s.singleLineResults, s.showPackageURLs)
}

s.logger.Println(toPrint)
Expand Down
60 changes: 47 additions & 13 deletions pkg/query/query_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestSourceQueryBuilder(t *testing.T) {
targetMode parser.TargetMode
singleLineResults bool
searchBy string
showPackageURLs bool
wantResults []string
wantOutput []string
}
Expand Down Expand Up @@ -260,6 +261,37 @@ func TestSourceQueryBuilder(t *testing.T) {
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\tThe Linux ZEN kernel and modules\n",
},
},
{
desc: "sort-by-name showpackageurls",
search: []string{"linux"},
bottomUp: true,
separateSources: true,
sortBy: "name",
verbosity: Detailed,
showPackageURLs: true,
wantResults: []string{"linux-ck", "linux", "linux-zen"},
wantOutput: []string{
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\n The Linux-ck kernel and modules with ck's hrtimer patches\n Package URL: https://aur.archlinux.org/packages/linux-ck\n",
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux kernel and modules\n Package URL: https://archlinux.org/packages/core/any/linux\n",
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\n The Linux ZEN kernel and modules\n Package URL: https://archlinux.org/packages/core/any/linux-zen\n",
},
},
{
desc: "sort-by-name singleline showpackageurls",
search: []string{"linux"},
bottomUp: true,
separateSources: true,
sortBy: "name",
verbosity: Detailed,
singleLineResults: true,
showPackageURLs: true,
wantResults: []string{"linux-ck", "linux", "linux-zen"},
wantOutput: []string{
"\x1b[1m\x1b[34maur\x1b[0m\x1b[0m/\x1b[1mlinux-ck\x1b[0m \x1b[36m5.16.12-1\x1b[0m\x1b[1m (+450\x1b[0m \x1b[1m1.51) \x1b[0m\tThe Linux-ck kernel and modules with ck's hrtimer patches\tPackage URL: https://aur.archlinux.org/packages/linux-ck\n",
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\tThe Linux kernel and modules\tPackage URL: https://archlinux.org/packages/core/any/linux\n",
"\x1b[1m\x1b[33mcore\x1b[0m\x1b[0m/\x1b[1mlinux-zen\x1b[0m \x1b[36m5.16.0\x1b[0m\x1b[1m (1.0 B 1.0 B) \x1b[0m\tThe Linux ZEN kernel and modules\tPackage URL: https://archlinux.org/packages/core/any/linux-zen\n",
},
},
{
desc: "sort-by-name search-by-name",
search: []string{"linux-ck"},
Expand Down Expand Up @@ -293,20 +325,22 @@ func TestSourceQueryBuilder(t *testing.T) {
mockDB := mock.NewDB("core")
return []mock.IPackage{
&mock.Package{
PName: "linux",
PVersion: "5.16.0",
PDescription: "The Linux kernel and modules",
PSize: 1,
PISize: 1,
PDB: mockDB,
PName: "linux",
PVersion: "5.16.0",
PDescription: "The Linux kernel and modules",
PArchitecture: "any",
PSize: 1,
PISize: 1,
PDB: mockDB,
},
&mock.Package{
PName: "linux-zen",
PVersion: "5.16.0",
PDescription: "The Linux ZEN kernel and modules",
PSize: 1,
PISize: 1,
PDB: mockDB,
PName: "linux-zen",
PVersion: "5.16.0",
PDescription: "The Linux ZEN kernel and modules",
PArchitecture: "any",
PSize: 1,
PISize: 1,
PDB: mockDB,
},
}
},
Expand Down Expand Up @@ -344,7 +378,7 @@ func TestSourceQueryBuilder(t *testing.T) {
queryBuilder := NewSourceQueryBuilder(mockAUR,
text.NewLogger(w, io.Discard, strings.NewReader(""), false, "test"),
tc.sortBy, tc.targetMode, tc.searchBy, tc.bottomUp,
tc.singleLineResults, tc.separateSources)
tc.singleLineResults, tc.separateSources, tc.showPackageURLs)

queryBuilder.Execute(context.Background(), mockDB, tc.search)

Expand Down
39 changes: 26 additions & 13 deletions pkg/query/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ func aurPkgSearchString(
pkg *aur.Pkg,
dbExecutor db.Executor,
singleLineResults bool,
showPackageURLs bool,
) string {
lineEnding := "\n "
if singleLineResults {
lineEnding = "\t"
}

toPrint := text.Bold(text.ColorHash("aur")) + "/" + text.Bold(pkg.Name) +
" " + text.Cyan(pkg.Version) +
text.Bold(" (+"+strconv.Itoa(pkg.NumVotes)) +
Expand All @@ -73,19 +79,24 @@ func aurPkgSearchString(
}
}

if singleLineResults {
toPrint += "\t"
} else {
toPrint += "\n "
}

toPrint += lineEnding
toPrint += pkg.Description

if showPackageURLs {
toPrint += lineEnding
toPrint += "Package URL: https://aur.archlinux.org/packages/" + pkg.Name
}

return toPrint
}

// PrintSearch receives a RepoSearch type and outputs pretty text.
func syncPkgSearchString(pkg alpm.IPackage, dbExecutor db.Executor, singleLineResults bool) string {
func syncPkgSearchString(pkg alpm.IPackage, dbExecutor db.Executor, singleLineResults, showPackageURLs bool) string {
lineEnding := "\n "
if singleLineResults {
lineEnding = "\t"
}

toPrint := text.Bold(text.ColorHash(pkg.DB().Name())) + "/" + text.Bold(pkg.Name()) +
" " + text.Cyan(pkg.Version()) +
text.Bold(" ("+text.Human(pkg.Size())+
Expand All @@ -104,13 +115,15 @@ func syncPkgSearchString(pkg alpm.IPackage, dbExecutor db.Executor, singleLineRe
}
}

if singleLineResults {
toPrint += "\t"
} else {
toPrint += "\n "
}

toPrint += lineEnding
toPrint += pkg.Description()
if showPackageURLs {
toPrint += lineEnding
toPrint += fmt.Sprintf(
"Package URL: https://archlinux.org/packages/%s/%s/%s",
pkg.DB().Name(), pkg.Architecture(), pkg.Name(),
)
}

return toPrint
}
2 changes: 1 addition & 1 deletion pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func NewRuntime(cfg *settings.Configuration, cmdArgs *parser.Arguments, version
aurClient,
logger.Child("mixed.querybuilder"), cfg.SortBy,
cfg.Mode, cfg.SearchBy,
cfg.BottomUp, cfg.SingleLineResults, cfg.SeparateSources)
cfg.BottomUp, cfg.SingleLineResults, cfg.SeparateSources, cfg.ShowPackageURLs)

run := &Runtime{
Cfg: cfg,
Expand Down
2 changes: 2 additions & 0 deletions pkg/settings/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (c *Configuration) handleOption(option, value string) bool {
c.SingleLineResults = true
case "doublelineresults":
c.SingleLineResults = false
case "showpackageurls":
c.ShowPackageURLs = boolValue
case "completioninterval":
n, err := strconv.Atoi(value)
if err == nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Configuration struct {
BatchInstall bool `json:"batchinstall"`
SingleLineResults bool `json:"singlelineresults"`
SeparateSources bool `json:"separatesources"`
ShowPackageURLs bool `json:"showpackageurls"`
Debug bool `json:"debug"`
UseRPC bool `json:"rpc"`
DoubleConfirm bool `json:"doubleconfirm"` // confirm install before and after build
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ func isArg(arg string) bool {
case "singlelineresults":
case "doublelineresults":
case "separatesources":
case "showpackageurls":
default:
return false
}
Expand Down
2 changes: 1 addition & 1 deletion query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func TestSyncSearchAURDB(t *testing.T) {
CmdBuilder: cmdBuilder,
AURClient: mockAUR,
QueryBuilder: query.NewSourceQueryBuilder(mockAUR, newTestLogger(), "votes", parser.ModeAny, "name",
tc.bottomUp, tc.singleLine, tc.mixed),
tc.bottomUp, tc.singleLine, tc.mixed, false),
Logger: newTestLogger(),
Cfg: &settings.Configuration{},
}
Expand Down
Loading