2017-08-02 17:24:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-05-08 04:06:25 +00:00
|
|
|
"bufio"
|
2018-05-06 00:26:03 +00:00
|
|
|
"bytes"
|
|
|
|
"encoding/xml"
|
2017-08-02 17:24:03 +00:00
|
|
|
"fmt"
|
2018-05-06 00:26:03 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2018-02-19 17:36:33 +00:00
|
|
|
"os"
|
2018-01-26 01:18:49 +00:00
|
|
|
"strconv"
|
2018-01-07 17:36:31 +00:00
|
|
|
"strings"
|
2018-03-02 04:54:38 +00:00
|
|
|
"time"
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2020-05-04 07:24:32 +00:00
|
|
|
"github.com/leonelquinteros/gotext"
|
2020-05-02 14:17:20 +00:00
|
|
|
rpc "github.com/mikkeloscar/aur"
|
2019-10-16 21:36:08 +00:00
|
|
|
|
2020-06-13 17:29:50 +00:00
|
|
|
"github.com/Jguer/yay/v10/pkg/intrange"
|
|
|
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
|
|
|
"github.com/Jguer/yay/v10/pkg/text"
|
2017-08-02 17:24:03 +00:00
|
|
|
)
|
|
|
|
|
2018-01-26 01:18:49 +00:00
|
|
|
const arrow = "==>"
|
2018-04-11 03:43:51 +00:00
|
|
|
const smallArrow = " ->"
|
|
|
|
|
2018-05-20 15:17:05 +00:00
|
|
|
func (warnings *aurWarnings) print() {
|
2018-04-11 03:43:51 +00:00
|
|
|
if len(warnings.Missing) > 0 {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Warn(gotext.Get("Missing AUR Packages:"))
|
2018-04-11 03:43:51 +00:00
|
|
|
for _, name := range warnings.Missing {
|
|
|
|
fmt.Print(" " + cyan(name))
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(warnings.Orphans) > 0 {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Warn(gotext.Get("Orphaned AUR Packages:"))
|
2018-04-11 03:43:51 +00:00
|
|
|
for _, name := range warnings.Orphans {
|
|
|
|
fmt.Print(" " + cyan(name))
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(warnings.OutOfDate) > 0 {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Warn(gotext.Get("Flagged Out Of Date AUR Packages:"))
|
2018-04-11 03:43:51 +00:00
|
|
|
for _, name := range warnings.OutOfDate {
|
|
|
|
fmt.Print(" " + cyan(name))
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
}
|
2018-01-26 01:18:49 +00:00
|
|
|
|
2017-08-02 17:24:03 +00:00
|
|
|
// PrintSearch handles printing search results in a given format
|
|
|
|
func (q aurQuery) printSearch(start int) {
|
2019-02-04 16:56:02 +00:00
|
|
|
localDB, _ := alpmHandle.LocalDB()
|
2017-08-02 17:24:03 +00:00
|
|
|
|
2020-05-02 14:17:20 +00:00
|
|
|
for i := range q {
|
2017-08-02 17:24:03 +00:00
|
|
|
var toprint string
|
2018-09-14 19:18:59 +00:00
|
|
|
if config.SearchMode == numberMenu {
|
2019-04-04 08:22:33 +00:00
|
|
|
switch config.SortMode {
|
|
|
|
case topDown:
|
2018-03-02 04:54:38 +00:00
|
|
|
toprint += magenta(strconv.Itoa(start+i) + " ")
|
2019-04-04 08:22:33 +00:00
|
|
|
case bottomUp:
|
|
|
|
toprint += magenta(strconv.Itoa(len(q)+start-i-1) + " ")
|
|
|
|
default:
|
2020-05-08 16:13:51 +00:00
|
|
|
text.Warnln(gotext.Get("invalid sort mode. Fix with yay -Y --bottomup --save"))
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-09-14 19:18:59 +00:00
|
|
|
} else if config.SearchMode == minimal {
|
2020-05-02 14:17:20 +00:00
|
|
|
fmt.Println(q[i].Name)
|
2017-08-02 17:24:03 +00:00
|
|
|
continue
|
|
|
|
}
|
2018-03-02 04:54:38 +00:00
|
|
|
|
2020-06-26 07:03:45 +00:00
|
|
|
toprint += bold(text.ColorHash("aur")) + "/" + bold(q[i].Name) +
|
2020-05-02 14:17:20 +00:00
|
|
|
" " + cyan(q[i].Version) +
|
|
|
|
bold(" (+"+strconv.Itoa(q[i].NumVotes)) +
|
2020-06-07 12:29:47 +00:00
|
|
|
" " + bold(strconv.FormatFloat(q[i].Popularity, 'f', 2, 64)+") ")
|
2018-01-26 01:18:49 +00:00
|
|
|
|
2020-05-02 14:17:20 +00:00
|
|
|
if q[i].Maintainer == "" {
|
2020-05-04 07:24:32 +00:00
|
|
|
toprint += bold(red(gotext.Get("(Orphaned)"))) + " "
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 14:17:20 +00:00
|
|
|
if q[i].OutOfDate != 0 {
|
2020-06-26 07:15:36 +00:00
|
|
|
toprint += bold(red(gotext.Get("(Out-of-date: %s)", text.FormatTime(q[i].OutOfDate)))) + " "
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 14:17:20 +00:00
|
|
|
if pkg := localDB.Pkg(q[i].Name); pkg != nil {
|
|
|
|
if pkg.Version() != q[i].Version {
|
2020-05-08 16:13:51 +00:00
|
|
|
toprint += bold(green(gotext.Get("(Installed: %s)", pkg.Version())))
|
2018-04-07 22:02:10 +00:00
|
|
|
} else {
|
2020-05-04 07:24:32 +00:00
|
|
|
toprint += bold(green(gotext.Get("(Installed)")))
|
2018-04-07 22:02:10 +00:00
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2020-05-02 14:17:20 +00:00
|
|
|
toprint += "\n " + q[i].Description
|
2017-08-02 17:24:03 +00:00
|
|
|
fmt.Println(toprint)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// PrintSearch receives a RepoSearch type and outputs pretty text.
|
2017-08-02 17:24:03 +00:00
|
|
|
func (s repoQuery) printSearch() {
|
|
|
|
for i, res := range s {
|
|
|
|
var toprint string
|
2018-09-14 19:18:59 +00:00
|
|
|
if config.SearchMode == numberMenu {
|
2019-04-04 08:22:33 +00:00
|
|
|
switch config.SortMode {
|
|
|
|
case topDown:
|
2018-03-02 04:54:38 +00:00
|
|
|
toprint += magenta(strconv.Itoa(i+1) + " ")
|
2019-04-04 08:22:33 +00:00
|
|
|
case bottomUp:
|
|
|
|
toprint += magenta(strconv.Itoa(len(s)-i) + " ")
|
|
|
|
default:
|
2020-05-08 16:13:51 +00:00
|
|
|
text.Warnln(gotext.Get("invalid sort mode. Fix with yay -Y --bottomup --save"))
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-09-14 19:18:59 +00:00
|
|
|
} else if config.SearchMode == minimal {
|
2017-08-02 17:24:03 +00:00
|
|
|
fmt.Println(res.Name())
|
|
|
|
continue
|
|
|
|
}
|
2018-03-02 04:54:38 +00:00
|
|
|
|
2020-06-26 07:03:45 +00:00
|
|
|
toprint += bold(text.ColorHash(res.DB().Name())) + "/" + bold(res.Name()) +
|
2018-03-02 04:54:38 +00:00
|
|
|
" " + cyan(res.Version()) +
|
2020-06-26 07:03:45 +00:00
|
|
|
bold(" ("+text.Human(res.Size())+
|
|
|
|
" "+text.Human(res.ISize())+") ")
|
2017-08-02 17:24:03 +00:00
|
|
|
|
|
|
|
if len(res.Groups().Slice()) != 0 {
|
|
|
|
toprint += fmt.Sprint(res.Groups().Slice(), " ")
|
|
|
|
}
|
|
|
|
|
2019-02-04 16:56:02 +00:00
|
|
|
localDB, err := alpmHandle.LocalDB()
|
2017-08-02 17:24:03 +00:00
|
|
|
if err == nil {
|
2019-02-14 20:44:39 +00:00
|
|
|
if pkg := localDB.Pkg(res.Name()); pkg != nil {
|
2018-04-07 22:02:10 +00:00
|
|
|
if pkg.Version() != res.Version() {
|
2020-05-04 07:24:32 +00:00
|
|
|
toprint += bold(green(gotext.Get("(Installed: %s)", pkg.Version())))
|
2018-04-07 22:02:10 +00:00
|
|
|
} else {
|
2020-05-04 07:24:32 +00:00
|
|
|
toprint += bold(green(gotext.Get("(Installed)")))
|
2018-04-07 22:02:10 +00:00
|
|
|
}
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toprint += "\n " + res.Description()
|
|
|
|
fmt.Println(toprint)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
// Pretty print a set of packages from the same package base.
|
|
|
|
// Packages foo and bar from a pkgbase named base would print like so:
|
|
|
|
// base (foo bar)
|
2020-05-02 14:17:20 +00:00
|
|
|
func (b Base) String() string {
|
|
|
|
pkg := b[0]
|
2018-02-20 01:23:16 +00:00
|
|
|
str := pkg.PackageBase
|
2020-05-02 14:17:20 +00:00
|
|
|
if len(b) > 1 || pkg.PackageBase != pkg.Name {
|
2018-02-20 01:23:16 +00:00
|
|
|
str2 := " ("
|
2020-05-02 14:17:20 +00:00
|
|
|
for _, split := range b {
|
2018-02-20 01:23:16 +00:00
|
|
|
str2 += split.Name + " "
|
|
|
|
}
|
|
|
|
str2 = str2[:len(str2)-1] + ")"
|
|
|
|
|
|
|
|
str += str2
|
|
|
|
}
|
|
|
|
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
2020-06-26 07:03:45 +00:00
|
|
|
func (u *upgrade) StylizedNameWithRepository() string {
|
|
|
|
return bold(text.ColorHash(u.Repository)) + "/" + bold(u.Name)
|
2018-05-02 15:46:21 +00:00
|
|
|
}
|
|
|
|
|
2018-03-11 03:51:00 +00:00
|
|
|
// Print prints the details of the packages to upgrade.
|
2018-05-20 15:17:05 +00:00
|
|
|
func (u upSlice) print() {
|
2018-05-02 15:46:21 +00:00
|
|
|
longestName, longestVersion := 0, 0
|
|
|
|
for _, pack := range u {
|
|
|
|
packNameLen := len(pack.StylizedNameWithRepository())
|
2020-05-02 14:17:20 +00:00
|
|
|
packVersion, _ := getVersionDiff(pack.LocalVersion, pack.RemoteVersion)
|
|
|
|
packVersionLen := len(packVersion)
|
2019-10-16 21:36:08 +00:00
|
|
|
longestName = intrange.Max(packNameLen, longestName)
|
|
|
|
longestVersion = intrange.Max(packVersionLen, longestVersion)
|
2018-05-02 15:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namePadding := fmt.Sprintf("%%-%ds ", longestName)
|
|
|
|
versionPadding := fmt.Sprintf("%%-%ds", longestVersion)
|
|
|
|
numberPadding := fmt.Sprintf("%%%dd ", len(fmt.Sprintf("%v", len(u))))
|
|
|
|
|
2018-03-11 03:51:00 +00:00
|
|
|
for k, i := range u {
|
|
|
|
left, right := getVersionDiff(i.LocalVersion, i.RemoteVersion)
|
|
|
|
|
2018-05-02 15:46:21 +00:00
|
|
|
fmt.Print(magenta(fmt.Sprintf(numberPadding, len(u)-k)))
|
|
|
|
|
|
|
|
fmt.Printf(namePadding, i.StylizedNameWithRepository())
|
2018-03-11 03:51:00 +00:00
|
|
|
|
2018-05-02 15:46:21 +00:00
|
|
|
fmt.Printf("%s -> %s\n", fmt.Sprintf(versionPadding, left), right)
|
2018-03-11 03:51:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-07 02:36:53 +00:00
|
|
|
// Print prints repository packages to be downloaded
|
2019-01-15 18:41:38 +00:00
|
|
|
func (do *depOrder) Print() {
|
|
|
|
repo := ""
|
|
|
|
repoMake := ""
|
|
|
|
aur := ""
|
|
|
|
aurMake := ""
|
|
|
|
|
|
|
|
repoLen := 0
|
|
|
|
repoMakeLen := 0
|
|
|
|
aurLen := 0
|
|
|
|
aurMakeLen := 0
|
|
|
|
|
|
|
|
for _, pkg := range do.Repo {
|
2019-10-05 17:39:31 +00:00
|
|
|
if do.Runtime.Get(pkg.Name()) {
|
2019-01-15 18:41:38 +00:00
|
|
|
repo += " " + pkg.Name() + "-" + pkg.Version()
|
|
|
|
repoLen++
|
|
|
|
} else {
|
|
|
|
repoMake += " " + pkg.Name() + "-" + pkg.Version()
|
|
|
|
repoMakeLen++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, base := range do.Aur {
|
|
|
|
pkg := base.Pkgbase()
|
|
|
|
pkgStr := " " + pkg + "-" + base[0].Version
|
|
|
|
pkgStrMake := pkgStr
|
|
|
|
|
|
|
|
push := false
|
|
|
|
pushMake := false
|
|
|
|
|
2019-03-07 20:02:44 +00:00
|
|
|
switch {
|
|
|
|
case len(base) > 1, pkg != base[0].Name:
|
2019-01-15 18:41:38 +00:00
|
|
|
pkgStr += " ("
|
|
|
|
pkgStrMake += " ("
|
|
|
|
|
|
|
|
for _, split := range base {
|
2019-10-05 17:39:31 +00:00
|
|
|
if do.Runtime.Get(split.Name) {
|
2019-01-15 18:41:38 +00:00
|
|
|
pkgStr += split.Name + " "
|
|
|
|
aurLen++
|
|
|
|
push = true
|
|
|
|
} else {
|
|
|
|
pkgStrMake += split.Name + " "
|
|
|
|
aurMakeLen++
|
|
|
|
pushMake = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgStr = pkgStr[:len(pkgStr)-1] + ")"
|
|
|
|
pkgStrMake = pkgStrMake[:len(pkgStrMake)-1] + ")"
|
2019-10-05 17:39:31 +00:00
|
|
|
case do.Runtime.Get(base[0].Name):
|
2019-01-15 18:41:38 +00:00
|
|
|
aurLen++
|
|
|
|
push = true
|
2019-03-07 20:02:44 +00:00
|
|
|
default:
|
2019-01-15 18:41:38 +00:00
|
|
|
aurMakeLen++
|
|
|
|
pushMake = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if push {
|
|
|
|
aur += pkgStr
|
|
|
|
}
|
|
|
|
if pushMake {
|
|
|
|
aurMake += pkgStrMake
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printDownloads("Repo", repoLen, repo)
|
|
|
|
printDownloads("Repo Make", repoMakeLen, repoMake)
|
|
|
|
printDownloads("Aur", aurLen, aur)
|
|
|
|
printDownloads("Aur Make", aurMakeLen, aurMake)
|
|
|
|
}
|
|
|
|
|
2018-02-15 21:23:34 +00:00
|
|
|
func printDownloads(repoName string, length int, packages string) {
|
|
|
|
if length < 1 {
|
|
|
|
return
|
2018-02-05 20:05:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 04:03:09 +00:00
|
|
|
repoInfo := bold(blue(
|
|
|
|
"[" + repoName + ": " + strconv.Itoa(length) + "]"))
|
2018-04-10 23:45:58 +00:00
|
|
|
fmt.Println(repoInfo + cyan(packages))
|
2018-02-05 20:05:58 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 17:24:03 +00:00
|
|
|
// PrintInfo prints package info like pacman -Si.
|
|
|
|
func PrintInfo(a *rpc.Pkg) {
|
2020-05-04 07:24:32 +00: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 07:15:36 +00:00
|
|
|
text.PrintInfoValue(gotext.Get("First Submitted"), text.FormatTimeQuery(a.FirstSubmitted))
|
|
|
|
text.PrintInfoValue(gotext.Get("Last Modified"), text.FormatTimeQuery(a.LastModified))
|
2018-07-24 00:48:36 +00:00
|
|
|
|
2017-08-02 17:24:03 +00:00
|
|
|
if a.OutOfDate != 0 {
|
2020-06-26 07:15:36 +00:00
|
|
|
text.PrintInfoValue(gotext.Get("Out-of-date"), text.FormatTimeQuery(a.OutOfDate))
|
2018-05-30 15:00:40 +00:00
|
|
|
} else {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.PrintInfoValue(gotext.Get("Out-of-date"), "No")
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
2018-01-07 17:36:31 +00:00
|
|
|
|
2018-07-24 00:48:36 +00:00
|
|
|
if cmdArgs.existsDouble("i") {
|
2020-05-04 07:24:32 +00: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 00:48:36 +00:00
|
|
|
}
|
|
|
|
|
2018-01-07 17:36:31 +00:00
|
|
|
fmt.Println()
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BiggestPackages prints the name of the ten biggest packages in the system.
|
|
|
|
func biggestPackages() {
|
2019-02-04 16:56:02 +00:00
|
|
|
localDB, err := alpmHandle.LocalDB()
|
2017-08-02 17:24:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-04 16:56:02 +00:00
|
|
|
pkgCache := localDB.PkgCache()
|
2017-08-02 17:24:03 +00:00
|
|
|
pkgS := pkgCache.SortBySize().Slice()
|
|
|
|
|
|
|
|
if len(pkgS) < 10 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
2020-06-26 07:03:45 +00:00
|
|
|
fmt.Printf("%s: %s\n", bold(pkgS[i].Name()), cyan(text.Human(pkgS[i].ISize())))
|
2017-08-02 17:24:03 +00:00
|
|
|
}
|
|
|
|
// Could implement size here as well, but we just want the general idea
|
|
|
|
}
|
2017-10-19 05:59:26 +00:00
|
|
|
|
|
|
|
// localStatistics prints installed packages statistics.
|
|
|
|
func localStatistics() error {
|
|
|
|
info, err := statistics()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, _, remoteNames, err := filterPackages()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Infoln(gotext.Get("Yay version v%s", yayVersion))
|
2018-03-02 04:03:09 +00:00
|
|
|
fmt.Println(bold(cyan("===========================================")))
|
2020-05-04 07:24:32 +00: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 07:03:45 +00:00
|
|
|
text.Infoln(gotext.Get("Total Size occupied by packages: %s", cyan(text.Human(info.TotalSize))))
|
2018-03-02 04:03:09 +00:00
|
|
|
fmt.Println(bold(cyan("===========================================")))
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Infoln(gotext.Get("Ten biggest packages:"))
|
2017-10-19 05:59:26 +00:00
|
|
|
biggestPackages()
|
2018-03-02 04:03:09 +00:00
|
|
|
fmt.Println(bold(cyan("===========================================")))
|
2017-10-19 05:59:26 +00:00
|
|
|
|
2018-04-11 03:43:51 +00:00
|
|
|
aurInfoPrint(remoteNames)
|
2017-10-19 05:59:26 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2018-01-17 21:48:23 +00:00
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
//TODO: Make it less hacky
|
2018-01-25 20:39:26 +00:00
|
|
|
func printNumberOfUpdates() error {
|
2020-01-17 19:51:29 +00:00
|
|
|
warnings := makeWarnings()
|
2018-02-19 17:36:33 +00:00
|
|
|
old := os.Stdout // keep backup of the real stdout
|
2018-01-25 20:39:26 +00:00
|
|
|
os.Stdout = nil
|
2018-04-11 03:43:51 +00:00
|
|
|
aurUp, repoUp, err := upList(warnings)
|
2018-01-25 20:39:26 +00:00
|
|
|
os.Stdout = old // restoring the real stdout
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Println(len(aurUp) + len(repoUp))
|
2018-02-21 08:41:25 +00:00
|
|
|
|
2018-01-25 20:39:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-03-03 02:45:16 +00:00
|
|
|
//TODO: Make it less hacky
|
2018-03-21 04:50:54 +00:00
|
|
|
func printUpdateList(parser *arguments) error {
|
2019-10-16 21:58:55 +00:00
|
|
|
targets := stringset.FromSlice(parser.targets)
|
2020-01-17 19:51:29 +00:00
|
|
|
warnings := makeWarnings()
|
2018-03-29 02:42:11 +00:00
|
|
|
old := os.Stdout // keep backup of the real stdout
|
2018-01-25 20:39:26 +00:00
|
|
|
os.Stdout = nil
|
2018-02-19 17:36:33 +00:00
|
|
|
_, _, localNames, remoteNames, err := filterPackages()
|
2018-04-27 00:25:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-04-11 03:43:51 +00:00
|
|
|
aurUp, repoUp, err := upList(warnings)
|
2018-03-29 02:42:11 +00:00
|
|
|
os.Stdout = old // restoring the real stdout
|
2018-01-25 20:39:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-21 04:50:54 +00:00
|
|
|
|
2018-06-02 14:01:39 +00:00
|
|
|
noTargets := len(targets) == 0
|
2018-03-21 04:50:54 +00:00
|
|
|
|
2018-05-12 13:41:32 +00:00
|
|
|
if !parser.existsArg("m", "foreign") {
|
2018-03-21 04:50:54 +00:00
|
|
|
for _, pkg := range repoUp {
|
2019-10-05 17:39:31 +00:00
|
|
|
if noTargets || targets.Get(pkg.Name) {
|
2018-09-24 09:52:17 +00:00
|
|
|
if parser.existsArg("q", "quiet") {
|
|
|
|
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 14:01:39 +00:00
|
|
|
delete(targets, pkg.Name)
|
2018-03-21 04:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !parser.existsArg("n", "native") {
|
|
|
|
for _, pkg := range aurUp {
|
2019-10-05 17:39:31 +00:00
|
|
|
if noTargets || targets.Get(pkg.Name) {
|
2018-09-24 09:52:17 +00:00
|
|
|
if parser.existsArg("q", "quiet") {
|
|
|
|
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 14:01:39 +00:00
|
|
|
delete(targets, pkg.Name)
|
2018-03-21 04:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-25 20:39:26 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 19:49:51 +00:00
|
|
|
missing := false
|
|
|
|
|
|
|
|
outer:
|
2018-06-02 14:01:39 +00:00
|
|
|
for pkg := range targets {
|
2018-03-23 19:49:51 +00:00
|
|
|
for _, name := range localNames {
|
|
|
|
if name == pkg {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range remoteNames {
|
|
|
|
if name == pkg {
|
|
|
|
continue outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Errorln(gotext.Get("package '%s' was not found", pkg))
|
2018-03-23 19:49:51 +00:00
|
|
|
missing = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if missing {
|
|
|
|
return fmt.Errorf("")
|
2018-01-25 20:39:26 +00:00
|
|
|
}
|
2018-02-19 17:36:33 +00:00
|
|
|
|
2018-01-25 20:39:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-01-26 01:18:49 +00:00
|
|
|
|
2018-05-20 15:17:05 +00:00
|
|
|
type item struct {
|
2018-05-06 21:04:04 +00:00
|
|
|
Title string `xml:"title"`
|
|
|
|
Link string `xml:"link"`
|
|
|
|
Description string `xml:"description"`
|
|
|
|
PubDate string `xml:"pubDate"`
|
|
|
|
Creator string `xml:"dc:creator"`
|
|
|
|
}
|
|
|
|
|
2020-05-02 14:17:20 +00:00
|
|
|
func (item *item) print(buildTime time.Time) {
|
2018-05-16 15:59:46 +00:00
|
|
|
var fd string
|
2018-05-06 21:04:04 +00:00
|
|
|
date, err := time.Parse(time.RFC1123Z, item.PubDate)
|
|
|
|
|
|
|
|
if err != nil {
|
2018-11-14 12:14:41 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2018-05-16 15:59:46 +00:00
|
|
|
} else {
|
2020-06-26 07:15:36 +00:00
|
|
|
fd = text.FormatTime(int(date.Unix()))
|
2018-05-17 19:09:43 +00:00
|
|
|
if _, double, _ := cmdArgs.getArg("news", "w"); !double && !buildTime.IsZero() {
|
|
|
|
if buildTime.After(date) {
|
2018-05-16 15:59:46 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-05-06 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 00:25:47 +00:00
|
|
|
fmt.Println(bold(magenta(fd)), bold(strings.TrimSpace(item.Title)))
|
|
|
|
|
|
|
|
if !cmdArgs.existsArg("q", "quiet") {
|
|
|
|
desc := strings.TrimSpace(parseNews(item.Description))
|
|
|
|
fmt.Println(desc)
|
|
|
|
}
|
2018-05-06 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
2018-05-20 15:17:05 +00:00
|
|
|
type channel struct {
|
2018-05-06 21:04:04 +00:00
|
|
|
Title string `xml:"title"`
|
|
|
|
Link string `xml:"link"`
|
|
|
|
Description string `xml:"description"`
|
|
|
|
Language string `xml:"language"`
|
|
|
|
Lastbuilddate string `xml:"lastbuilddate"`
|
2018-05-20 15:17:05 +00:00
|
|
|
Items []item `xml:"item"`
|
2018-05-06 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
2018-05-06 00:26:03 +00:00
|
|
|
type rss struct {
|
2018-05-20 15:17:05 +00:00
|
|
|
Channel channel `xml:"channel"`
|
2018-05-06 00:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func printNewsFeed() error {
|
|
|
|
resp, err := http.Get("https://archlinux.org/feeds/news")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-02 14:17:20 +00:00
|
|
|
rssGot := rss{}
|
2018-05-06 00:26:03 +00:00
|
|
|
|
2018-05-06 02:25:23 +00:00
|
|
|
d := xml.NewDecoder(bytes.NewReader(body))
|
2020-05-02 14:17:20 +00:00
|
|
|
err = d.Decode(&rssGot)
|
2018-05-06 00:26:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-17 19:09:43 +00:00
|
|
|
buildTime, err := lastBuildTime()
|
2018-05-16 15:59:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-14 19:18:59 +00:00
|
|
|
if config.SortMode == bottomUp {
|
2020-05-02 14:17:20 +00:00
|
|
|
for i := len(rssGot.Channel.Items) - 1; i >= 0; i-- {
|
|
|
|
rssGot.Channel.Items[i].print(buildTime)
|
2018-05-06 21:04:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-05-02 14:17:20 +00:00
|
|
|
for i := 0; i < len(rssGot.Channel.Items); i++ {
|
|
|
|
rssGot.Channel.Items[i].print(buildTime)
|
2018-05-06 02:25:23 +00:00
|
|
|
}
|
2018-05-06 00:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-04-07 22:19:16 +00:00
|
|
|
const (
|
|
|
|
redCode = "\x1b[31m"
|
|
|
|
greenCode = "\x1b[32m"
|
|
|
|
yellowCode = "\x1b[33m"
|
|
|
|
blueCode = "\x1b[34m"
|
|
|
|
magentaCode = "\x1b[35m"
|
|
|
|
cyanCode = "\x1b[36m"
|
|
|
|
boldCode = "\x1b[1m"
|
|
|
|
|
|
|
|
resetCode = "\x1b[0m"
|
|
|
|
)
|
|
|
|
|
|
|
|
func stylize(startCode, in string) string {
|
2020-06-26 07:03:45 +00:00
|
|
|
if text.UseColor {
|
2018-04-07 22:19:16 +00:00
|
|
|
return startCode + in + resetCode
|
2018-01-26 01:18:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return in
|
|
|
|
}
|
|
|
|
|
2018-04-07 22:19:16 +00:00
|
|
|
func red(in string) string {
|
|
|
|
return stylize(redCode, in)
|
|
|
|
}
|
2018-01-26 01:18:49 +00:00
|
|
|
|
2018-04-07 22:19:16 +00:00
|
|
|
func green(in string) string {
|
|
|
|
return stylize(greenCode, in)
|
2018-01-26 01:18:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 04:03:09 +00:00
|
|
|
func yellow(in string) string {
|
2018-04-07 22:19:16 +00:00
|
|
|
return stylize(yellowCode, in)
|
2018-01-26 11:30:33 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 04:03:09 +00:00
|
|
|
func blue(in string) string {
|
2018-04-07 22:19:16 +00:00
|
|
|
return stylize(blueCode, in)
|
2018-01-26 01:18:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 04:03:09 +00:00
|
|
|
func cyan(in string) string {
|
2018-04-07 22:19:16 +00:00
|
|
|
return stylize(cyanCode, in)
|
2018-01-26 01:18:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 04:54:38 +00:00
|
|
|
func magenta(in string) string {
|
2018-04-07 22:19:16 +00:00
|
|
|
return stylize(magentaCode, in)
|
2018-01-26 01:18:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 04:03:09 +00:00
|
|
|
func bold(in string) string {
|
2018-04-07 22:19:16 +00:00
|
|
|
return stylize(boldCode, in)
|
2018-01-26 01:18:49 +00:00
|
|
|
}
|
2018-03-02 01:02:56 +00:00
|
|
|
|
2018-05-10 01:22:21 +00:00
|
|
|
func providerMenu(dep string, providers providers) *rpc.Pkg {
|
|
|
|
size := providers.Len()
|
2018-05-08 04:06:25 +00:00
|
|
|
|
2020-05-04 07:24:32 +00:00
|
|
|
str := bold(gotext.Get("There are %d providers available for %s:", size, dep))
|
2018-05-08 04:06:25 +00:00
|
|
|
|
|
|
|
size = 1
|
2020-05-04 07:24:32 +00:00
|
|
|
str += bold(cyan("\n:: ")) + bold(gotext.Get("Repository AUR")) + "\n "
|
2018-05-08 04:06:25 +00:00
|
|
|
|
2018-05-10 01:22:21 +00:00
|
|
|
for _, pkg := range providers.Pkgs {
|
2018-05-08 04:06:25 +00:00
|
|
|
str += fmt.Sprintf("%d) %s ", size, pkg.Name)
|
|
|
|
size++
|
|
|
|
}
|
|
|
|
|
2020-05-04 07:24:32 +00:00
|
|
|
text.OperationInfoln(str)
|
2018-05-08 04:06:25 +00:00
|
|
|
|
|
|
|
for {
|
2020-05-04 07:24:32 +00:00
|
|
|
fmt.Print(gotext.Get("\nEnter a number (default=1): "))
|
2018-05-08 04:06:25 +00:00
|
|
|
|
|
|
|
if config.NoConfirm {
|
2018-06-19 21:20:24 +00:00
|
|
|
fmt.Println("1")
|
|
|
|
return providers.Pkgs[0]
|
2018-05-08 04:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
numberBuf, overflow, err := reader.ReadLine()
|
|
|
|
|
|
|
|
if err != nil {
|
2018-11-14 12:14:41 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2018-05-08 04:06:25 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if overflow {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Errorln(gotext.Get("input too long"))
|
2018-05-08 04:06:25 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if string(numberBuf) == "" {
|
2018-05-10 01:22:21 +00:00
|
|
|
return providers.Pkgs[0]
|
2018-05-08 04:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
num, err := strconv.Atoi(string(numberBuf))
|
|
|
|
if err != nil {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Errorln(gotext.Get("invalid number: %s", string(numberBuf)))
|
2018-05-08 04:06:25 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2019-05-27 11:46:08 +00:00
|
|
|
if num < 1 || num >= size {
|
2020-05-04 07:24:32 +00:00
|
|
|
text.Errorln(gotext.Get("invalid value: %d is not between %d and %d", num, 1, size-1))
|
2018-05-08 04:06:25 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-05-10 01:22:21 +00:00
|
|
|
return providers.Pkgs[num-1]
|
2018-05-08 04:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|