2017-08-02 19:24:03 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-02-19 18:36:33 +01:00
|
|
|
"os"
|
2018-01-26 02:18:49 +01:00
|
|
|
"strconv"
|
2018-01-07 18:36:31 +01:00
|
|
|
"strings"
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
"github.com/leonelquinteros/gotext"
|
2020-05-02 16:17:20 +02:00
|
|
|
rpc "github.com/mikkeloscar/aur"
|
2019-10-16 23:36:08 +02:00
|
|
|
|
2020-08-01 00:01:01 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/db"
|
2020-07-05 02:01:08 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/query"
|
|
|
|
"github.com/Jguer/yay/v10/pkg/settings"
|
2020-06-13 19:29:50 +02:00
|
|
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
|
|
|
"github.com/Jguer/yay/v10/pkg/text"
|
2017-08-02 19:24:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// PrintSearch handles printing search results in a given format
|
2020-08-16 23:41:38 +02:00
|
|
|
func (q aurQuery) printSearch(start int, dbExecutor db.Executor) {
|
2020-05-02 16:17:20 +02:00
|
|
|
for i := range q {
|
2017-08-02 19:24:03 +02:00
|
|
|
var toprint string
|
2018-09-14 21:18:59 +02:00
|
|
|
if config.SearchMode == numberMenu {
|
2019-04-04 10:22:33 +02:00
|
|
|
switch config.SortMode {
|
2020-07-05 02:01:08 +02:00
|
|
|
case settings.TopDown:
|
2018-03-02 05:54:38 +01:00
|
|
|
toprint += magenta(strconv.Itoa(start+i) + " ")
|
2020-07-05 02:01:08 +02:00
|
|
|
case settings.BottomUp:
|
2019-04-04 10:22:33 +02:00
|
|
|
toprint += magenta(strconv.Itoa(len(q)+start-i-1) + " ")
|
|
|
|
default:
|
2020-05-08 18:13:51 +02:00
|
|
|
text.Warnln(gotext.Get("invalid sort mode. Fix with yay -Y --bottomup --save"))
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-09-14 21:18:59 +02:00
|
|
|
} else if config.SearchMode == minimal {
|
2020-05-02 16:17:20 +02:00
|
|
|
fmt.Println(q[i].Name)
|
2017-08-02 19:24:03 +02:00
|
|
|
continue
|
|
|
|
}
|
2018-03-02 05:54:38 +01:00
|
|
|
|
2020-06-26 09:03:45 +02:00
|
|
|
toprint += bold(text.ColorHash("aur")) + "/" + bold(q[i].Name) +
|
2020-05-02 16:17:20 +02:00
|
|
|
" " + cyan(q[i].Version) +
|
|
|
|
bold(" (+"+strconv.Itoa(q[i].NumVotes)) +
|
2020-06-07 14:29:47 +02:00
|
|
|
" " + bold(strconv.FormatFloat(q[i].Popularity, 'f', 2, 64)+") ")
|
2018-01-26 02:18:49 +01:00
|
|
|
|
2020-05-02 16:17:20 +02:00
|
|
|
if q[i].Maintainer == "" {
|
2020-05-04 09:24:32 +02:00
|
|
|
toprint += bold(red(gotext.Get("(Orphaned)"))) + " "
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2020-05-02 16:17:20 +02:00
|
|
|
if q[i].OutOfDate != 0 {
|
2020-06-26 09:15:36 +02:00
|
|
|
toprint += bold(red(gotext.Get("(Out-of-date: %s)", text.FormatTime(q[i].OutOfDate)))) + " "
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-01 00:01:01 +02:00
|
|
|
if pkg := dbExecutor.LocalPackage(q[i].Name); pkg != nil {
|
2020-05-02 16:17:20 +02:00
|
|
|
if pkg.Version() != q[i].Version {
|
2020-05-08 18:13:51 +02:00
|
|
|
toprint += bold(green(gotext.Get("(Installed: %s)", pkg.Version())))
|
2018-04-08 00:02:10 +02:00
|
|
|
} else {
|
2020-05-04 09:24:32 +02:00
|
|
|
toprint += bold(green(gotext.Get("(Installed)")))
|
2018-04-08 00:02:10 +02:00
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2020-05-02 16:17:20 +02:00
|
|
|
toprint += "\n " + q[i].Description
|
2017-08-02 19:24:03 +02:00
|
|
|
fmt.Println(toprint)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// PrintSearch receives a RepoSearch type and outputs pretty text.
|
2020-08-16 23:41:38 +02:00
|
|
|
func (s repoQuery) printSearch(dbExecutor db.Executor) {
|
2017-08-02 19:24:03 +02:00
|
|
|
for i, res := range s {
|
|
|
|
var toprint string
|
2018-09-14 21:18:59 +02:00
|
|
|
if config.SearchMode == numberMenu {
|
2019-04-04 10:22:33 +02:00
|
|
|
switch config.SortMode {
|
2020-07-05 02:01:08 +02:00
|
|
|
case settings.TopDown:
|
2018-03-02 05:54:38 +01:00
|
|
|
toprint += magenta(strconv.Itoa(i+1) + " ")
|
2020-07-05 02:01:08 +02:00
|
|
|
case settings.BottomUp:
|
2019-04-04 10:22:33 +02:00
|
|
|
toprint += magenta(strconv.Itoa(len(s)-i) + " ")
|
|
|
|
default:
|
2020-05-08 18:13:51 +02:00
|
|
|
text.Warnln(gotext.Get("invalid sort mode. Fix with yay -Y --bottomup --save"))
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-09-14 21:18:59 +02:00
|
|
|
} else if config.SearchMode == minimal {
|
2017-08-02 19:24:03 +02:00
|
|
|
fmt.Println(res.Name())
|
|
|
|
continue
|
|
|
|
}
|
2018-03-02 05:54:38 +01:00
|
|
|
|
2020-06-26 09:03:45 +02:00
|
|
|
toprint += bold(text.ColorHash(res.DB().Name())) + "/" + bold(res.Name()) +
|
2018-03-02 05:54:38 +01:00
|
|
|
" " + cyan(res.Version()) +
|
2020-06-26 09:03:45 +02:00
|
|
|
bold(" ("+text.Human(res.Size())+
|
|
|
|
" "+text.Human(res.ISize())+") ")
|
2017-08-02 19:24:03 +02:00
|
|
|
|
2020-08-01 00:01:01 +02:00
|
|
|
packageGroups := dbExecutor.PackageGroups(res)
|
|
|
|
if len(packageGroups) != 0 {
|
|
|
|
toprint += fmt.Sprint(packageGroups, " ")
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-01 00:01:01 +02:00
|
|
|
if pkg := dbExecutor.LocalPackage(res.Name()); pkg != nil {
|
|
|
|
if pkg.Version() != res.Version() {
|
|
|
|
toprint += bold(green(gotext.Get("(Installed: %s)", pkg.Version())))
|
|
|
|
} else {
|
|
|
|
toprint += bold(green(gotext.Get("(Installed)")))
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toprint += "\n " + res.Description()
|
|
|
|
fmt.Println(toprint)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// Pretty print a set of packages from the same package base.
|
2018-02-20 02:23:16 +01:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
// PrintInfo prints package info like pacman -Si.
|
2020-07-08 03:22:01 +02:00
|
|
|
func PrintInfo(a *rpc.Pkg, extendedInfo bool) {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.PrintInfoValue(gotext.Get("Repository"), "aur")
|
|
|
|
text.PrintInfoValue(gotext.Get("Name"), a.Name)
|
|
|
|
text.PrintInfoValue(gotext.Get("Keywords"), strings.Join(a.Keywords, " "))
|
|
|
|
text.PrintInfoValue(gotext.Get("Version"), a.Version)
|
|
|
|
text.PrintInfoValue(gotext.Get("Description"), a.Description)
|
|
|
|
text.PrintInfoValue(gotext.Get("URL"), a.URL)
|
|
|
|
text.PrintInfoValue(gotext.Get("AUR URL"), config.AURURL+"/packages/"+a.Name)
|
|
|
|
text.PrintInfoValue(gotext.Get("Groups"), strings.Join(a.Groups, " "))
|
|
|
|
text.PrintInfoValue(gotext.Get("Licenses"), strings.Join(a.License, " "))
|
|
|
|
text.PrintInfoValue(gotext.Get("Provides"), strings.Join(a.Provides, " "))
|
|
|
|
text.PrintInfoValue(gotext.Get("Depends On"), strings.Join(a.Depends, " "))
|
|
|
|
text.PrintInfoValue(gotext.Get("Make Deps"), strings.Join(a.MakeDepends, " "))
|
|
|
|
text.PrintInfoValue(gotext.Get("Check Deps"), strings.Join(a.CheckDepends, " "))
|
|
|
|
text.PrintInfoValue(gotext.Get("Optional Deps"), strings.Join(a.OptDepends, " "))
|
|
|
|
text.PrintInfoValue(gotext.Get("Conflicts With"), strings.Join(a.Conflicts, " "))
|
|
|
|
text.PrintInfoValue(gotext.Get("Maintainer"), a.Maintainer)
|
|
|
|
text.PrintInfoValue(gotext.Get("Votes"), fmt.Sprintf("%d", a.NumVotes))
|
|
|
|
text.PrintInfoValue(gotext.Get("Popularity"), fmt.Sprintf("%f", a.Popularity))
|
2020-06-26 09:15:36 +02:00
|
|
|
text.PrintInfoValue(gotext.Get("First Submitted"), text.FormatTimeQuery(a.FirstSubmitted))
|
|
|
|
text.PrintInfoValue(gotext.Get("Last Modified"), text.FormatTimeQuery(a.LastModified))
|
2018-07-24 02:48:36 +02:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
if a.OutOfDate != 0 {
|
2020-06-26 09:15:36 +02:00
|
|
|
text.PrintInfoValue(gotext.Get("Out-of-date"), text.FormatTimeQuery(a.OutOfDate))
|
2018-05-30 17:00:40 +02:00
|
|
|
} else {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.PrintInfoValue(gotext.Get("Out-of-date"), "No")
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2018-01-07 18:36:31 +01:00
|
|
|
|
2020-07-08 03:22:01 +02:00
|
|
|
if extendedInfo {
|
2020-05-04 09:24:32 +02:00
|
|
|
text.PrintInfoValue("ID", fmt.Sprintf("%d", a.ID))
|
|
|
|
text.PrintInfoValue(gotext.Get("Package Base ID"), fmt.Sprintf("%d", a.PackageBaseID))
|
|
|
|
text.PrintInfoValue(gotext.Get("Package Base"), a.PackageBase)
|
|
|
|
text.PrintInfoValue(gotext.Get("Snapshot URL"), config.AURURL+a.URLPath)
|
2018-07-24 02:48:36 +02:00
|
|
|
}
|
|
|
|
|
2018-01-07 18:36:31 +01:00
|
|
|
fmt.Println()
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BiggestPackages prints the name of the ten biggest packages in the system.
|
2020-08-16 23:41:38 +02:00
|
|
|
func biggestPackages(dbExecutor db.Executor) {
|
2020-08-04 22:00:07 +02:00
|
|
|
pkgS := dbExecutor.BiggestPackages()
|
2017-08-02 19:24:03 +02:00
|
|
|
|
|
|
|
if len(pkgS) < 10 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
2020-06-26 09:03:45 +02:00
|
|
|
fmt.Printf("%s: %s\n", bold(pkgS[i].Name()), cyan(text.Human(pkgS[i].ISize())))
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
// Could implement size here as well, but we just want the general idea
|
|
|
|
}
|
2017-10-19 07:59:26 +02:00
|
|
|
|
|
|
|
// localStatistics prints installed packages statistics.
|
2020-08-16 23:41:38 +02:00
|
|
|
func localStatistics(dbExecutor db.Executor) error {
|
2020-08-04 22:00:07 +02:00
|
|
|
info := statistics(dbExecutor)
|
2017-10-19 07:59:26 +02:00
|
|
|
|
2020-08-01 01:20:00 +02:00
|
|
|
_, remoteNames, err := query.GetPackageNamesBySource(config.Runtime.DBExecutor)
|
2017-10-19 07:59:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Infoln(gotext.Get("Yay version v%s", yayVersion))
|
2018-03-02 05:03:09 +01:00
|
|
|
fmt.Println(bold(cyan("===========================================")))
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Infoln(gotext.Get("Total installed packages: %s", cyan(strconv.Itoa(info.Totaln))))
|
|
|
|
text.Infoln(gotext.Get("Total foreign installed packages: %s", cyan(strconv.Itoa(len(remoteNames)))))
|
|
|
|
text.Infoln(gotext.Get("Explicitly installed packages: %s", cyan(strconv.Itoa(info.Expln))))
|
2020-06-26 09:03:45 +02:00
|
|
|
text.Infoln(gotext.Get("Total Size occupied by packages: %s", cyan(text.Human(info.TotalSize))))
|
2018-03-02 05:03:09 +01:00
|
|
|
fmt.Println(bold(cyan("===========================================")))
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Infoln(gotext.Get("Ten biggest packages:"))
|
2020-08-04 22:00:07 +02:00
|
|
|
biggestPackages(dbExecutor)
|
2018-03-02 05:03:09 +01:00
|
|
|
fmt.Println(bold(cyan("===========================================")))
|
2017-10-19 07:59:26 +02:00
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
query.AURInfoPrint(remoteNames, config.RequestSplitN)
|
2017-10-19 07:59:26 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2018-01-17 22:48:23 +01:00
|
|
|
|
2020-07-08 03:40:50 +02:00
|
|
|
// TODO: Make it less hacky
|
2020-08-16 23:41:38 +02:00
|
|
|
func printNumberOfUpdates(dbExecutor db.Executor, enableDowngrade bool) error {
|
2020-07-10 02:36:45 +02:00
|
|
|
warnings := query.NewWarnings()
|
2018-02-19 18:36:33 +01:00
|
|
|
old := os.Stdout // keep backup of the real stdout
|
2018-01-25 21:39:26 +01:00
|
|
|
os.Stdout = nil
|
2020-08-01 09:55:08 +02:00
|
|
|
aurUp, repoUp, err := upList(warnings, dbExecutor, enableDowngrade)
|
2018-01-25 21:39:26 +01:00
|
|
|
os.Stdout = old // restoring the real stdout
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(len(aurUp) + len(repoUp))
|
2018-02-21 09:41:25 +01:00
|
|
|
|
2018-01-25 21:39:26 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-08 03:40:50 +02:00
|
|
|
// TODO: Make it less hacky
|
2020-08-16 23:41:38 +02:00
|
|
|
func printUpdateList(cmdArgs *settings.Arguments, dbExecutor db.Executor, enableDowngrade bool) error {
|
2020-07-08 03:22:01 +02:00
|
|
|
targets := stringset.FromSlice(cmdArgs.Targets)
|
2020-07-10 02:36:45 +02:00
|
|
|
warnings := query.NewWarnings()
|
2018-03-29 04:42:11 +02:00
|
|
|
old := os.Stdout // keep backup of the real stdout
|
2018-01-25 21:39:26 +01:00
|
|
|
os.Stdout = nil
|
2020-08-01 09:55:08 +02:00
|
|
|
localNames, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
|
2018-04-27 02:25:40 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-01 09:55:08 +02:00
|
|
|
aurUp, repoUp, err := upList(warnings, dbExecutor, enableDowngrade)
|
2018-03-29 04:42:11 +02:00
|
|
|
os.Stdout = old // restoring the real stdout
|
2018-01-25 21:39:26 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-21 05:50:54 +01:00
|
|
|
|
2018-06-02 16:01:39 +02:00
|
|
|
noTargets := len(targets) == 0
|
2018-03-21 05:50:54 +01:00
|
|
|
|
2020-07-08 03:22:01 +02:00
|
|
|
if !cmdArgs.ExistsArg("m", "foreign") {
|
2018-03-21 05:50:54 +01:00
|
|
|
for _, pkg := range repoUp {
|
2019-10-05 19:39:31 +02:00
|
|
|
if noTargets || targets.Get(pkg.Name) {
|
2020-07-08 03:22:01 +02:00
|
|
|
if cmdArgs.ExistsArg("q", "quiet") {
|
2018-09-24 11:52:17 +02:00
|
|
|
fmt.Printf("%s\n", pkg.Name)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%s %s -> %s\n", bold(pkg.Name), green(pkg.LocalVersion), green(pkg.RemoteVersion))
|
|
|
|
}
|
2018-06-02 16:01:39 +02:00
|
|
|
delete(targets, pkg.Name)
|
2018-03-21 05:50:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 03:22:01 +02:00
|
|
|
if !cmdArgs.ExistsArg("n", "native") {
|
2018-03-21 05:50:54 +01:00
|
|
|
for _, pkg := range aurUp {
|
2019-10-05 19:39:31 +02:00
|
|
|
if noTargets || targets.Get(pkg.Name) {
|
2020-07-08 03:22:01 +02:00
|
|
|
if cmdArgs.ExistsArg("q", "quiet") {
|
2018-09-24 11:52:17 +02:00
|
|
|
fmt.Printf("%s\n", pkg.Name)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%s %s -> %s\n", bold(pkg.Name), green(pkg.LocalVersion), green(pkg.RemoteVersion))
|
|
|
|
}
|
2018-06-02 16:01:39 +02:00
|
|
|
delete(targets, pkg.Name)
|
2018-03-21 05:50:54 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-25 21:39:26 +01:00
|
|
|
}
|
|
|
|
|
2018-03-23 20:49:51 +01:00
|
|
|
missing := false
|
|
|
|
|
|
|
|
outer:
|
2018-06-02 16:01:39 +02:00
|
|
|
for pkg := range targets {
|
2018-03-23 20:49:51 +01:00
|
|
|
for _, name := range localNames {
|
|
|
|
if name == pkg {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range remoteNames {
|
|
|
|
if name == pkg {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:24:32 +02:00
|
|
|
text.Errorln(gotext.Get("package '%s' was not found", pkg))
|
2018-03-23 20:49:51 +01:00
|
|
|
missing = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if missing {
|
|
|
|
return fmt.Errorf("")
|
2018-01-25 21:39:26 +01:00
|
|
|
}
|
2018-02-19 18:36:33 +01:00
|
|
|
|
2018-01-25 21:39:26 +01:00
|
|
|
return nil
|
|
|
|
}
|
2018-01-26 02:18:49 +01:00
|
|
|
|
2018-04-08 00:19:16 +02:00
|
|
|
const (
|
|
|
|
redCode = "\x1b[31m"
|
|
|
|
greenCode = "\x1b[32m"
|
|
|
|
blueCode = "\x1b[34m"
|
|
|
|
magentaCode = "\x1b[35m"
|
|
|
|
cyanCode = "\x1b[36m"
|
|
|
|
boldCode = "\x1b[1m"
|
|
|
|
|
|
|
|
resetCode = "\x1b[0m"
|
|
|
|
)
|
|
|
|
|
|
|
|
func stylize(startCode, in string) string {
|
2020-06-26 09:03:45 +02:00
|
|
|
if text.UseColor {
|
2018-04-08 00:19:16 +02:00
|
|
|
return startCode + in + resetCode
|
2018-01-26 02:18:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return in
|
|
|
|
}
|
|
|
|
|
2018-04-08 00:19:16 +02:00
|
|
|
func red(in string) string {
|
|
|
|
return stylize(redCode, in)
|
|
|
|
}
|
2018-01-26 02:18:49 +01:00
|
|
|
|
2018-04-08 00:19:16 +02:00
|
|
|
func green(in string) string {
|
|
|
|
return stylize(greenCode, in)
|
2018-01-26 02:18:49 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:03:09 +01:00
|
|
|
func blue(in string) string {
|
2018-04-08 00:19:16 +02:00
|
|
|
return stylize(blueCode, in)
|
2018-01-26 02:18:49 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:03:09 +01:00
|
|
|
func cyan(in string) string {
|
2018-04-08 00:19:16 +02:00
|
|
|
return stylize(cyanCode, in)
|
2018-01-26 02:18:49 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:54:38 +01:00
|
|
|
func magenta(in string) string {
|
2018-04-08 00:19:16 +02:00
|
|
|
return stylize(magentaCode, in)
|
2018-01-26 02:18:49 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:03:09 +01:00
|
|
|
func bold(in string) string {
|
2018-04-08 00:19:16 +02:00
|
|
|
return stylize(boldCode, in)
|
2018-01-26 02:18:49 +01:00
|
|
|
}
|