diff --git a/cmd_test.go b/cmd_test.go index 5f3a3cddd..15d4d5c23 100644 --- a/cmd_test.go +++ b/cmd_test.go @@ -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) diff --git a/completions/bash b/completions/bash index 20d9bf45f..f4885f19f 100644 --- a/completions/bash +++ b/completions/bash @@ -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 diff --git a/completions/fish b/completions/fish index 6d5a6d5ed..ac22124ed 100644 --- a/completions/fish +++ b/completions/fish @@ -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 diff --git a/completions/zsh b/completions/zsh index 1bbf1f93a..1d682a9cc 100644 --- a/completions/zsh +++ b/completions/zsh @@ -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]' diff --git a/doc/yay.8 b/doc/yay.8 index d196889e4..68ca5b59a 100644 --- a/doc/yay.8 +++ b/doc/yay.8 @@ -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 diff --git a/pkg/db/mock/repo.go b/pkg/db/mock/repo.go index d8feae539..1e334183c 100644 --- a/pkg/db/mock/repo.go +++ b/pkg/db/mock/repo.go @@ -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 @@ -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. diff --git a/pkg/query/query_builder.go b/pkg/query/query_builder.go index e607f9ebb..cace9583f 100644 --- a/pkg/query/query_builder.go +++ b/pkg/query/query_builder.go @@ -47,6 +47,7 @@ type SourceQueryBuilder struct { bottomUp bool singleLineResults bool separateSources bool + showPackageURLs bool aurClient aur.QueryClient logger *text.Logger @@ -61,6 +62,7 @@ func NewSourceQueryBuilder( bottomUp, singleLineResults bool, separateSources bool, + showPackageURLs bool, ) *SourceQueryBuilder { return &SourceQueryBuilder{ aurClient: aurClient, @@ -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), } @@ -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) diff --git a/pkg/query/query_builder_test.go b/pkg/query/query_builder_test.go index 6d87bfed7..1c1ac40de 100644 --- a/pkg/query/query_builder_test.go +++ b/pkg/query/query_builder_test.go @@ -31,6 +31,7 @@ func TestSourceQueryBuilder(t *testing.T) { targetMode parser.TargetMode singleLineResults bool searchBy string + showPackageURLs bool wantResults []string wantOutput []string } @@ -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"}, @@ -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, }, } }, @@ -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) diff --git a/pkg/query/types.go b/pkg/query/types.go index 2b1583483..9a132b073 100644 --- a/pkg/query/types.go +++ b/pkg/query/types.go @@ -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)) + @@ -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())+ @@ -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 } diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index 499ee4f08..8b6da1f60 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -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, diff --git a/pkg/settings/args.go b/pkg/settings/args.go index 974125941..409274718 100644 --- a/pkg/settings/args.go +++ b/pkg/settings/args.go @@ -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 { diff --git a/pkg/settings/config.go b/pkg/settings/config.go index aba88249b..8e10711e0 100644 --- a/pkg/settings/config.go +++ b/pkg/settings/config.go @@ -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 diff --git a/pkg/settings/parser/parser.go b/pkg/settings/parser/parser.go index 08063a69c..b4c913f95 100644 --- a/pkg/settings/parser/parser.go +++ b/pkg/settings/parser/parser.go @@ -439,6 +439,7 @@ func isArg(arg string) bool { case "singlelineresults": case "doublelineresults": case "separatesources": + case "showpackageurls": default: return false } diff --git a/query_test.go b/query_test.go index 11231a9c5..f2333ed8a 100644 --- a/query_test.go +++ b/query_test.go @@ -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{}, }