2017-08-02 19:24:03 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-05-08 06:06:25 +02:00
|
|
|
"bufio"
|
2018-05-06 02:26:03 +02:00
|
|
|
"bytes"
|
|
|
|
"encoding/xml"
|
2017-08-02 19:24:03 +02:00
|
|
|
"fmt"
|
2018-05-06 02:26:03 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
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"
|
2018-03-02 05:54:38 +01:00
|
|
|
"time"
|
2017-08-02 19:24:03 +02:00
|
|
|
|
|
|
|
rpc "github.com/mikkeloscar/aur"
|
|
|
|
)
|
|
|
|
|
2018-01-26 02:18:49 +01:00
|
|
|
const arrow = "==>"
|
2018-04-11 05:43:51 +02:00
|
|
|
const smallArrow = " ->"
|
|
|
|
|
2018-05-20 17:17:05 +02:00
|
|
|
func (warnings *aurWarnings) print() {
|
2018-04-11 05:43:51 +02:00
|
|
|
if len(warnings.Missing) > 0 {
|
|
|
|
fmt.Print(bold(yellow(smallArrow)) + " Missing AUR Packages:")
|
|
|
|
for _, name := range warnings.Missing {
|
|
|
|
fmt.Print(" " + cyan(name))
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(warnings.Orphans) > 0 {
|
|
|
|
fmt.Print(bold(yellow(smallArrow)) + " Orphaned AUR Packages:")
|
|
|
|
for _, name := range warnings.Orphans {
|
|
|
|
fmt.Print(" " + cyan(name))
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(warnings.OutOfDate) > 0 {
|
|
|
|
fmt.Print(bold(yellow(smallArrow)) + " Out Of Date AUR Packages:")
|
|
|
|
for _, name := range warnings.OutOfDate {
|
|
|
|
fmt.Print(" " + cyan(name))
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-01-26 02:18:49 +01:00
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// human method returns results in human readable format.
|
2017-08-02 19:24:03 +02:00
|
|
|
func human(size int64) string {
|
|
|
|
floatsize := float32(size)
|
|
|
|
units := [...]string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
|
|
|
|
for _, unit := range units {
|
|
|
|
if floatsize < 1024 {
|
|
|
|
return fmt.Sprintf("%.1f %sB", floatsize, unit)
|
|
|
|
}
|
|
|
|
floatsize /= 1024
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%d%s", size, "B")
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrintSearch handles printing search results in a given format
|
|
|
|
func (q aurQuery) printSearch(start int) {
|
2017-10-18 04:38:19 +02:00
|
|
|
localDb, _ := alpmHandle.LocalDb()
|
2017-08-02 19:24:03 +02:00
|
|
|
|
|
|
|
for i, res := range q {
|
|
|
|
var toprint string
|
2017-08-04 11:26:53 +02:00
|
|
|
if config.SearchMode == NumberMenu {
|
|
|
|
if config.SortMode == BottomUp {
|
2018-03-02 05:54:38 +01:00
|
|
|
toprint += magenta(strconv.Itoa(len(q)+start-i-1) + " ")
|
2017-08-02 19:24:03 +02:00
|
|
|
} else {
|
2018-03-02 05:54:38 +01:00
|
|
|
toprint += magenta(strconv.Itoa(start+i) + " ")
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
2017-08-04 11:26:53 +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
|
|
|
|
|
|
|
toprint += bold(colourHash("aur")) + "/" + bold(res.Name) +
|
|
|
|
" " + cyan(res.Version) +
|
|
|
|
bold(" (+"+strconv.Itoa(res.NumVotes)) +
|
|
|
|
" " + bold(strconv.FormatFloat(res.Popularity, 'f', 2, 64)+"%) ")
|
2018-01-26 02:18:49 +01:00
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
if res.Maintainer == "" {
|
2018-03-02 05:54:38 +01:00
|
|
|
toprint += bold(red("(Orphaned)")) + " "
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if res.OutOfDate != 0 {
|
2018-03-02 05:54:38 +01:00
|
|
|
toprint += bold(red("(Out-of-date "+formatTime(res.OutOfDate)+")")) + " "
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
|
2018-04-08 00:02:10 +02:00
|
|
|
if pkg, err := localDb.PkgByName(res.Name); err == nil {
|
|
|
|
if pkg.Version() != res.Version {
|
|
|
|
toprint += bold(green("(Installed: " + pkg.Version() + ")"))
|
|
|
|
} else {
|
|
|
|
toprint += bold(green("(Installed)"))
|
|
|
|
}
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
toprint += "\n " + res.Description
|
|
|
|
fmt.Println(toprint)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// PrintSearch receives a RepoSearch type and outputs pretty text.
|
2017-08-02 19:24:03 +02:00
|
|
|
func (s repoQuery) printSearch() {
|
|
|
|
for i, res := range s {
|
|
|
|
var toprint string
|
|
|
|
if config.SearchMode == NumberMenu {
|
|
|
|
if config.SortMode == BottomUp {
|
2018-03-02 05:54:38 +01:00
|
|
|
toprint += magenta(strconv.Itoa(len(s)-i) + " ")
|
2017-08-02 19:24:03 +02:00
|
|
|
} else {
|
2018-03-02 05:54:38 +01:00
|
|
|
toprint += magenta(strconv.Itoa(i+1) + " ")
|
2017-08-02 19:24:03 +02:00
|
|
|
}
|
|
|
|
} else if config.SearchMode == Minimal {
|
|
|
|
fmt.Println(res.Name())
|
|
|
|
continue
|
|
|
|
}
|
2018-03-02 05:54:38 +01:00
|
|
|
|
|
|
|
toprint += bold(colourHash(res.DB().Name())) + "/" + bold(res.Name()) +
|
|
|
|
" " + cyan(res.Version()) +
|
|
|
|
bold(" ("+human(res.Size())+
|
|
|
|
" "+human(res.ISize())+") ")
|
2017-08-02 19:24:03 +02:00
|
|
|
|
|
|
|
if len(res.Groups().Slice()) != 0 {
|
|
|
|
toprint += fmt.Sprint(res.Groups().Slice(), " ")
|
|
|
|
}
|
|
|
|
|
2017-10-18 04:38:19 +02:00
|
|
|
localDb, err := alpmHandle.LocalDb()
|
2017-08-02 19:24:03 +02:00
|
|
|
if err == nil {
|
2018-04-08 00:02:10 +02:00
|
|
|
if pkg, err := localDb.PkgByName(res.Name()); err == nil {
|
|
|
|
if pkg.Version() != res.Version() {
|
|
|
|
toprint += bold(green("(Installed: " + pkg.Version() + ")"))
|
|
|
|
} else {
|
|
|
|
toprint += bold(green("(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.
|
|
|
|
// Packages foo and bar from a pkgbase named base would print like so:
|
|
|
|
// base (foo bar)
|
2018-02-20 02:23:16 +01:00
|
|
|
func formatPkgbase(pkg *rpc.Pkg, bases map[string][]*rpc.Pkg) string {
|
|
|
|
str := pkg.PackageBase
|
|
|
|
if len(bases[pkg.PackageBase]) > 1 || pkg.PackageBase != pkg.Name {
|
|
|
|
str2 := " ("
|
|
|
|
for _, split := range bases[pkg.PackageBase] {
|
|
|
|
str2 += split.Name + " "
|
|
|
|
}
|
|
|
|
str2 = str2[:len(str2)-1] + ")"
|
|
|
|
|
|
|
|
str += str2
|
|
|
|
}
|
|
|
|
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:46:21 +02:00
|
|
|
func (u upgrade) StylizedNameWithRepository() string {
|
|
|
|
return bold(colourHash(u.Repository)) + "/" + bold(u.Name)
|
|
|
|
}
|
|
|
|
|
2018-03-11 04:51:00 +01:00
|
|
|
// Print prints the details of the packages to upgrade.
|
2018-05-20 17:17:05 +02:00
|
|
|
func (u upSlice) print() {
|
2018-05-02 17:46:21 +02:00
|
|
|
longestName, longestVersion := 0, 0
|
|
|
|
for _, pack := range u {
|
|
|
|
packNameLen := len(pack.StylizedNameWithRepository())
|
|
|
|
version, _ := getVersionDiff(pack.LocalVersion, pack.RemoteVersion)
|
|
|
|
packVersionLen := len(version)
|
|
|
|
longestName = max(packNameLen, longestName)
|
|
|
|
longestVersion = max(packVersionLen, longestVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
namePadding := fmt.Sprintf("%%-%ds ", longestName)
|
|
|
|
versionPadding := fmt.Sprintf("%%-%ds", longestVersion)
|
|
|
|
numberPadding := fmt.Sprintf("%%%dd ", len(fmt.Sprintf("%v", len(u))))
|
|
|
|
|
2018-03-11 04:51:00 +01:00
|
|
|
for k, i := range u {
|
|
|
|
left, right := getVersionDiff(i.LocalVersion, i.RemoteVersion)
|
|
|
|
|
2018-05-02 17:46:21 +02:00
|
|
|
fmt.Print(magenta(fmt.Sprintf(numberPadding, len(u)-k)))
|
|
|
|
|
|
|
|
fmt.Printf(namePadding, i.StylizedNameWithRepository())
|
2018-03-11 04:51:00 +01:00
|
|
|
|
2018-05-02 17:46:21 +02:00
|
|
|
fmt.Printf("%s -> %s\n", fmt.Sprintf(versionPadding, left), right)
|
2018-03-11 04:51:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-05 21:05:58 +01:00
|
|
|
// printDownloadsFromRepo prints repository packages to be downloaded
|
2018-05-08 06:41:04 +02:00
|
|
|
func (do *depOrder) Print() {
|
2018-02-15 22:23:34 +01:00
|
|
|
repo := ""
|
|
|
|
repoMake := ""
|
|
|
|
aur := ""
|
|
|
|
aurMake := ""
|
|
|
|
|
|
|
|
repoLen := 0
|
|
|
|
repoMakeLen := 0
|
|
|
|
aurLen := 0
|
|
|
|
aurMakeLen := 0
|
|
|
|
|
2018-05-08 06:41:04 +02:00
|
|
|
for _, pkg := range do.Repo {
|
|
|
|
if do.Runtime.get(pkg.Name()) {
|
2018-03-09 00:54:18 +01:00
|
|
|
repo += " " + pkg.Name() + "-" + pkg.Version()
|
2018-02-15 22:23:34 +01:00
|
|
|
repoLen++
|
2018-05-08 06:41:04 +02:00
|
|
|
} else {
|
|
|
|
repoMake += " " + pkg.Name() + "-" + pkg.Version()
|
|
|
|
repoMakeLen++
|
2018-02-15 22:23:34 +01:00
|
|
|
}
|
2018-02-05 21:05:58 +01:00
|
|
|
}
|
2018-02-15 22:23:34 +01:00
|
|
|
|
2018-05-08 06:41:04 +02:00
|
|
|
for _, pkg := range do.Aur {
|
2018-03-09 00:54:18 +01:00
|
|
|
pkgStr := " " + pkg.PackageBase + "-" + pkg.Version
|
2018-02-15 22:23:34 +01:00
|
|
|
pkgStrMake := pkgStr
|
|
|
|
|
|
|
|
push := false
|
|
|
|
pushMake := false
|
|
|
|
|
2018-05-08 06:41:04 +02:00
|
|
|
if len(do.Bases[pkg.PackageBase]) > 1 || pkg.PackageBase != pkg.Name {
|
2018-02-15 22:23:34 +01:00
|
|
|
pkgStr += " ("
|
|
|
|
pkgStrMake += " ("
|
|
|
|
|
2018-05-08 06:41:04 +02:00
|
|
|
for _, split := range do.Bases[pkg.PackageBase] {
|
|
|
|
if do.Runtime.get(split.Name) {
|
2018-02-15 22:23:34 +01:00
|
|
|
pkgStr += split.Name + " "
|
|
|
|
aurLen++
|
|
|
|
push = true
|
2018-05-08 06:41:04 +02:00
|
|
|
} else {
|
|
|
|
pkgStrMake += split.Name + " "
|
|
|
|
aurMakeLen++
|
|
|
|
pushMake = true
|
2018-02-15 22:23:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgStr = pkgStr[:len(pkgStr)-1] + ")"
|
|
|
|
pkgStrMake = pkgStrMake[:len(pkgStrMake)-1] + ")"
|
2018-05-08 06:41:04 +02:00
|
|
|
} else if do.Runtime.get(pkg.Name) {
|
2018-02-15 22:23:34 +01:00
|
|
|
aurLen++
|
|
|
|
push = true
|
2018-05-08 06:41:04 +02:00
|
|
|
} else {
|
|
|
|
aurMakeLen++
|
|
|
|
pushMake = true
|
2018-02-15 22:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if push {
|
|
|
|
aur += pkgStr
|
|
|
|
}
|
|
|
|
if pushMake {
|
|
|
|
aurMake += pkgStrMake
|
|
|
|
}
|
2018-02-05 21:05:58 +01:00
|
|
|
}
|
2018-02-15 22:23:34 +01:00
|
|
|
|
2018-02-16 18:18:59 +01:00
|
|
|
printDownloads("Repo", repoLen, repo)
|
|
|
|
printDownloads("Repo Make", repoMakeLen, repoMake)
|
|
|
|
printDownloads("Aur", aurLen, aur)
|
|
|
|
printDownloads("Aur Make", aurMakeLen, aurMake)
|
2018-02-05 21:05:58 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 22:23:34 +01:00
|
|
|
func printDownloads(repoName string, length int, packages string) {
|
|
|
|
if length < 1 {
|
|
|
|
return
|
2018-02-05 21:05:58 +01:00
|
|
|
}
|
|
|
|
|
2018-03-02 05:03:09 +01:00
|
|
|
repoInfo := bold(blue(
|
|
|
|
"[" + repoName + ": " + strconv.Itoa(length) + "]"))
|
2018-04-11 01:45:58 +02:00
|
|
|
fmt.Println(repoInfo + cyan(packages))
|
2018-02-05 21:05:58 +01:00
|
|
|
}
|
|
|
|
|
2018-05-30 17:00:40 +02:00
|
|
|
func printInfoValue(str, value string) {
|
|
|
|
fmt.Printf(bold("%-16s%s")+" %s\n", str, ":", value)
|
|
|
|
}
|
|
|
|
|
2017-08-02 19:24:03 +02:00
|
|
|
// PrintInfo prints package info like pacman -Si.
|
|
|
|
func PrintInfo(a *rpc.Pkg) {
|
2018-05-30 17:00:40 +02:00
|
|
|
printInfoValue("Repository", "aur")
|
|
|
|
printInfoValue("Name", a.Name)
|
|
|
|
printInfoValue("Version", a.Version)
|
|
|
|
printInfoValue("Description", a.Description)
|
|
|
|
printInfoValue("URL", a.URL)
|
|
|
|
printInfoValue("Licenses", strings.Join(a.License, " "))
|
|
|
|
printInfoValue("Provides", strings.Join(a.Provides, " "))
|
|
|
|
printInfoValue("Depends On", strings.Join(a.Depends, " "))
|
|
|
|
printInfoValue("Make Deps", strings.Join(a.MakeDepends, " "))
|
|
|
|
printInfoValue("Check Deps", strings.Join(a.CheckDepends, " "))
|
|
|
|
printInfoValue("Optional Deps", strings.Join(a.OptDepends, " "))
|
|
|
|
printInfoValue("Conflicts With", strings.Join(a.Conflicts, " "))
|
|
|
|
printInfoValue("Maintainer", a.Maintainer)
|
|
|
|
printInfoValue("Votes", fmt.Sprintf("%d", a.NumVotes))
|
|
|
|
printInfoValue("Popularity", fmt.Sprintf("%f", a.Popularity))
|
2017-08-02 19:24:03 +02:00
|
|
|
if a.OutOfDate != 0 {
|
2018-05-30 17:00:40 +02:00
|
|
|
printInfoValue("Out-of-date", "Yes ["+formatTime(a.OutOfDate)+"]")
|
|
|
|
} else {
|
|
|
|
printInfoValue("Out-of-date", "No")
|
2017-08-02 19:24:03 +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.
|
|
|
|
func biggestPackages() {
|
2017-10-18 04:38:19 +02:00
|
|
|
localDb, err := alpmHandle.LocalDb()
|
2017-08-02 19:24:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgCache := localDb.PkgCache()
|
|
|
|
pkgS := pkgCache.SortBySize().Slice()
|
|
|
|
|
|
|
|
if len(pkgS) < 10 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ {
|
2018-03-02 05:54:38 +01:00
|
|
|
fmt.Println(bold(pkgS[i].Name()) + ": " + cyan(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.
|
|
|
|
func localStatistics() error {
|
|
|
|
info, err := statistics()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, _, remoteNames, err := filterPackages()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-02 05:54:38 +01:00
|
|
|
fmt.Printf(bold("Yay version v%s\n"), version)
|
2018-03-02 05:03:09 +01:00
|
|
|
fmt.Println(bold(cyan("===========================================")))
|
2018-04-11 01:45:58 +02:00
|
|
|
fmt.Println(bold(green("Total installed packages: ")) + cyan(strconv.Itoa(info.Totaln)))
|
|
|
|
fmt.Println(bold(green("Total foreign installed packages: ")) + cyan(strconv.Itoa(len(remoteNames))))
|
|
|
|
fmt.Println(bold(green("Explicitly installed packages: ")) + cyan(strconv.Itoa(info.Expln)))
|
|
|
|
fmt.Println(bold(green("Total Size occupied by packages: ")) + cyan(human(info.TotalSize)))
|
2018-03-02 05:03:09 +01:00
|
|
|
fmt.Println(bold(cyan("===========================================")))
|
2018-03-02 05:54:38 +01:00
|
|
|
fmt.Println(bold(green("Ten biggest packages:")))
|
2017-10-19 07:59:26 +02:00
|
|
|
biggestPackages()
|
2018-03-02 05:03:09 +01:00
|
|
|
fmt.Println(bold(cyan("===========================================")))
|
2017-10-19 07:59:26 +02:00
|
|
|
|
2018-04-11 05:43:51 +02:00
|
|
|
aurInfoPrint(remoteNames)
|
2017-10-19 07:59:26 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2018-01-17 22:48:23 +01:00
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
//TODO: Make it less hacky
|
2018-01-25 21:39:26 +01:00
|
|
|
func printNumberOfUpdates() error {
|
2018-02-19 00:46:25 +01:00
|
|
|
//todo
|
2018-04-11 05:43:51 +02:00
|
|
|
warnings := &aurWarnings{}
|
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
|
2018-04-11 05:43:51 +02:00
|
|
|
aurUp, repoUp, err := upList(warnings)
|
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
|
|
|
|
}
|
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
//TODO: Make it less hacky
|
2018-03-21 05:50:54 +01:00
|
|
|
func printUpdateList(parser *arguments) error {
|
2018-06-02 16:01:39 +02:00
|
|
|
targets := sliceToStringSet(parser.targets)
|
2018-04-11 05:43:51 +02:00
|
|
|
warnings := &aurWarnings{}
|
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
|
2018-02-19 18:36:33 +01:00
|
|
|
_, _, localNames, remoteNames, err := filterPackages()
|
2018-04-27 02:25:40 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-04-11 05:43:51 +02:00
|
|
|
aurUp, repoUp, err := upList(warnings)
|
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
|
|
|
|
2018-05-12 15:41:32 +02:00
|
|
|
if !parser.existsArg("m", "foreign") {
|
2018-03-21 05:50:54 +01:00
|
|
|
for _, pkg := range repoUp {
|
2018-06-02 16:01:39 +02:00
|
|
|
if noTargets || targets.get(pkg.Name) {
|
2018-03-21 05:50:54 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !parser.existsArg("n", "native") {
|
|
|
|
for _, pkg := range aurUp {
|
2018-06-02 16:01:39 +02:00
|
|
|
if noTargets || targets.get(pkg.Name) {
|
2018-03-21 05:50:54 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 17:39:27 +01:00
|
|
|
fmt.Println(red(bold("error:")), "package '"+pkg+"' was not found")
|
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-05-20 17:17:05 +02:00
|
|
|
type item struct {
|
2018-05-06 23:04:04 +02:00
|
|
|
Title string `xml:"title"`
|
|
|
|
Link string `xml:"link"`
|
|
|
|
Description string `xml:"description"`
|
|
|
|
PubDate string `xml:"pubDate"`
|
|
|
|
Creator string `xml:"dc:creator"`
|
|
|
|
}
|
|
|
|
|
2018-05-20 17:17:05 +02:00
|
|
|
func (item item) print(buildTime time.Time) {
|
2018-05-16 17:59:46 +02:00
|
|
|
var fd string
|
2018-05-06 23:04:04 +02:00
|
|
|
date, err := time.Parse(time.RFC1123Z, item.PubDate)
|
|
|
|
|
|
|
|
if err != nil {
|
2018-05-16 17:59:46 +02:00
|
|
|
fmt.Println(err)
|
|
|
|
} else {
|
|
|
|
fd = formatTime(int(date.Unix()))
|
2018-05-17 21:09:43 +02:00
|
|
|
if _, double, _ := cmdArgs.getArg("news", "w"); !double && !buildTime.IsZero() {
|
|
|
|
if buildTime.After(date) {
|
2018-05-16 17:59:46 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2018-05-06 23:04:04 +02:00
|
|
|
}
|
|
|
|
|
2018-05-07 02:25:47 +02:00
|
|
|
fmt.Println(bold(magenta(fd)), bold(strings.TrimSpace(item.Title)))
|
|
|
|
//fmt.Println(strings.TrimSpace(item.Link))
|
|
|
|
|
|
|
|
if !cmdArgs.existsArg("q", "quiet") {
|
|
|
|
desc := strings.TrimSpace(parseNews(item.Description))
|
|
|
|
fmt.Println(desc)
|
|
|
|
}
|
2018-05-06 23:04:04 +02:00
|
|
|
}
|
|
|
|
|
2018-05-20 17:17:05 +02:00
|
|
|
type channel struct {
|
2018-05-06 23:04:04 +02:00
|
|
|
Title string `xml:"title"`
|
|
|
|
Link string `xml:"link"`
|
|
|
|
Description string `xml:"description"`
|
|
|
|
Language string `xml:"language"`
|
|
|
|
Lastbuilddate string `xml:"lastbuilddate"`
|
2018-05-20 17:17:05 +02:00
|
|
|
Items []item `xml:"item"`
|
2018-05-06 23:04:04 +02:00
|
|
|
}
|
|
|
|
|
2018-05-06 02:26:03 +02:00
|
|
|
type rss struct {
|
2018-05-20 17:17:05 +02:00
|
|
|
Channel channel `xml:"channel"`
|
2018-05-06 02:26:03 +02: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
|
|
|
|
}
|
|
|
|
|
|
|
|
rss := rss{}
|
|
|
|
|
2018-05-06 04:25:23 +02:00
|
|
|
d := xml.NewDecoder(bytes.NewReader(body))
|
|
|
|
err = d.Decode(&rss)
|
2018-05-06 02:26:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-17 21:09:43 +02:00
|
|
|
buildTime, err := lastBuildTime()
|
2018-05-16 17:59:46 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-06 23:04:04 +02:00
|
|
|
if config.SortMode == BottomUp {
|
|
|
|
for i := len(rss.Channel.Items) - 1; i >= 0; i-- {
|
2018-05-20 17:17:05 +02:00
|
|
|
rss.Channel.Items[i].print(buildTime)
|
2018-05-06 23:04:04 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for i := 0; i < len(rss.Channel.Items); i++ {
|
2018-05-20 17:17:05 +02:00
|
|
|
rss.Channel.Items[i].print(buildTime)
|
2018-05-06 04:25:23 +02:00
|
|
|
}
|
2018-05-06 02:26:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-05-04 12:36:14 +02:00
|
|
|
// Formats a unix timestamp to ISO 8601 date (yyyy-mm-dd)
|
2018-03-02 05:54:38 +01:00
|
|
|
func formatTime(i int) string {
|
|
|
|
t := time.Unix(int64(i), 0)
|
2018-05-04 12:36:14 +02:00
|
|
|
return t.Format("2006-01-02")
|
2018-03-02 05:54:38 +01:00
|
|
|
}
|
|
|
|
|
2018-04-08 00:19:16 +02: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 {
|
2018-03-21 06:34:54 +01:00
|
|
|
if 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 yellow(in string) string {
|
2018-04-08 00:19:16 +02:00
|
|
|
return stylize(yellowCode, in)
|
2018-01-26 12:30:33 +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
|
|
|
}
|
2018-03-02 02:02:56 +01:00
|
|
|
|
2018-03-03 03:45:16 +01:00
|
|
|
// Colours text using a hashing algorithm. The same text will always produce the
|
|
|
|
// same colour while different text will produce a different colour.
|
2018-03-02 02:02:56 +01:00
|
|
|
func colourHash(name string) (output string) {
|
2018-03-21 06:34:54 +01:00
|
|
|
if !useColor {
|
2018-03-02 02:02:56 +01:00
|
|
|
return name
|
|
|
|
}
|
|
|
|
var hash = 5381
|
|
|
|
for i := 0; i < len(name); i++ {
|
|
|
|
hash = int(name[i]) + ((hash << 5) + (hash))
|
|
|
|
}
|
2018-03-02 05:03:09 +01:00
|
|
|
return fmt.Sprintf("\x1b[%dm%s\x1b[0m", hash%6+31, name)
|
2018-03-02 02:02:56 +01:00
|
|
|
}
|
2018-05-08 06:06:25 +02:00
|
|
|
|
2018-05-10 03:22:21 +02:00
|
|
|
func providerMenu(dep string, providers providers) *rpc.Pkg {
|
|
|
|
size := providers.Len()
|
2018-05-08 06:06:25 +02:00
|
|
|
|
|
|
|
fmt.Print(bold(cyan(":: ")))
|
|
|
|
str := bold(fmt.Sprintf(bold("There are %d providers available for %s:"), size, dep))
|
|
|
|
|
|
|
|
size = 1
|
|
|
|
str += bold(cyan("\n:: ")) + bold("Repository AUR\n ")
|
|
|
|
|
2018-05-10 03:22:21 +02:00
|
|
|
for _, pkg := range providers.Pkgs {
|
2018-05-08 06:06:25 +02:00
|
|
|
str += fmt.Sprintf("%d) %s ", size, pkg.Name)
|
|
|
|
size++
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(str)
|
|
|
|
|
|
|
|
for {
|
|
|
|
fmt.Print("\nEnter a number (default=1): ")
|
|
|
|
|
|
|
|
if config.NoConfirm {
|
|
|
|
fmt.Println()
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
numberBuf, overflow, err := reader.ReadLine()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if overflow {
|
|
|
|
fmt.Println("Input too long")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if string(numberBuf) == "" {
|
2018-05-10 03:22:21 +02:00
|
|
|
return providers.Pkgs[0]
|
2018-05-08 06:06:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
num, err := strconv.Atoi(string(numberBuf))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s invalid number: %s\n", red("error:"), string(numberBuf))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if num < 1 || num > size {
|
|
|
|
fmt.Printf("%s invalid value: %d is not between %d and %d\n", red("error:"), num, 1, size)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-05-10 03:22:21 +02:00
|
|
|
return providers.Pkgs[num-1]
|
2018-05-08 06:06:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|