Merge pull request #349 from Morganamilo/fix#331

Lots of formatting tweaks
This commit is contained in:
J Guerreiro 2018-04-12 15:40:22 +01:00 committed by GitHub
commit aa649d9b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 153 additions and 116 deletions

View File

@ -34,7 +34,7 @@ func questionCallback(question alpm.QuestionAny) {
if db != thisDb { if db != thisDb {
db = thisDb db = thisDb
str += bold(cyan("\n:: ")) + bold("Repository "+db+"\n\t") str += bold(cyan("\n:: ")) + bold("Repository "+db+"\n ")
} }
str += fmt.Sprintf("%d) %s ", size, pkg.Name()) str += fmt.Sprintf("%d) %s ", size, pkg.Name())
size++ size++

View File

@ -187,11 +187,11 @@ func editor() (string, []string) {
fallthrough fallthrough
default: default:
fmt.Println() fmt.Println()
fmt.Println(bold(red(arrow)+" Warning:"), cyan("$EDITOR"), "is not set") fmt.Println(bold(red(arrow)), bold(cyan("$EDITOR")), bold("is not set"))
fmt.Println(bold(arrow) + " Please add " + cyan("$EDITOR") + " or " + cyan("$VISUAL") + " to your environment variables.") fmt.Println(bold(red(arrow)) + bold(" Please add ") + bold(cyan("$EDITOR")) + bold(" or ") + bold(cyan("$VISUAL")) + bold(" to your environment variables."))
for { for {
fmt.Print(green(bold(arrow)) + green(" Edit PKGBUILD with: ")) fmt.Print(green(bold(arrow + " Edit PKGBUILD with: ")))
editorInput, err := getInput("") editorInput, err := getInput("")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -225,7 +225,7 @@ func continueTask(s string, def string) (cont bool) {
} }
var response string var response string
fmt.Print(bold(green(arrow+" "+s+" ")), bold(postFix)) fmt.Print(bold(green(arrow)+" "+s), bold(postFix))
n, err := fmt.Scanln(&response) n, err := fmt.Scanln(&response)
if err != nil || n == 0 { if err != nil || n == 0 {

View File

@ -301,13 +301,13 @@ func checkForAllConflicts(dc *depCatagories) error {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
fmt.Println(bold(cyan("::") + " Checking for conflicts...")) fmt.Println(bold(cyan("::") + bold(" Checking for conflicts...")))
go func() { go func() {
conflicts, err = checkForConflicts(dc) conflicts, err = checkForConflicts(dc)
wg.Done() wg.Done()
}() }()
fmt.Println(bold(cyan("::") + " Checking for inner conflicts...")) fmt.Println(bold(cyan("::") + bold(" Checking for inner conflicts...")))
go func() { go func() {
innerConflicts = checkForInnerConflicts(dc) innerConflicts = checkForInnerConflicts(dc)
wg.Done() wg.Done()
@ -320,27 +320,28 @@ func checkForAllConflicts(dc *depCatagories) error {
} }
if len(innerConflicts) != 0 { if len(innerConflicts) != 0 {
fmt.Println( fmt.Println()
red("\nInner conflicts found:")) fmt.Println(bold(red(arrow)), bold("Inner conflicts found:"))
for name, pkgs := range innerConflicts { for name, pkgs := range innerConflicts {
str := "\t" + name + ":" str := red(bold(smallArrow)) + " " + name + ":"
for pkg := range pkgs { for pkg := range pkgs {
str += " " + magenta(pkg) str += " " + cyan(pkg)
} }
fmt.Println(str) fmt.Println(str)
} }
return fmt.Errorf("Aborting") return fmt.Errorf("Unresolvable package conflicts, aborting")
} }
if len(conflicts) != 0 { if len(conflicts) != 0 {
fmt.Println( fmt.Println()
red("\nPackage conflicts found:")) fmt.Println(bold(red(arrow)), bold("Package conflicts found:"))
for name, pkgs := range conflicts { for name, pkgs := range conflicts {
str := "\tInstalling " + magenta(name) + " will remove:" str := red(bold(smallArrow)) + " Installing " + cyan(name) + " will remove:"
for pkg := range pkgs { for pkg := range pkgs {
str += " " + magenta(pkg) str += " " + cyan(pkg)
} }
fmt.Println(str) fmt.Println(str)

View File

@ -16,6 +16,7 @@ type depTree struct {
Missing stringSet Missing stringSet
Groups stringSet Groups stringSet
Provides map[string]string Provides map[string]string
Warnings *aurWarnings
} }
type depCatagories struct { type depCatagories struct {
@ -33,6 +34,7 @@ func makeDepTree() *depTree {
make(stringSet), make(stringSet),
make(stringSet), make(stringSet),
make(map[string]string), make(map[string]string),
&aurWarnings{},
} }
return &dt return &dt
@ -325,8 +327,9 @@ func depCatagoriesRecursive(_pkg *rpc.Pkg, dc *depCatagories, dt *depTree, isMak
// the same as the height of the tree. // the same as the height of the tree.
// The example does not really do this justice, In the real world where packages // The example does not really do this justice, In the real world where packages
// have 10+ dependencies each this is a very nice optimization. // have 10+ dependencies each this is a very nice optimization.
func getDepTree(pkgs []string) (*depTree, error) { func getDepTree(pkgs []string, warnings *aurWarnings) (*depTree, error) {
dt := makeDepTree() dt := makeDepTree()
dt.Warnings = warnings
localDb, err := alpmHandle.LocalDb() localDb, err := alpmHandle.LocalDb()
if err != nil { if err != nil {
@ -382,7 +385,7 @@ func getDepTree(pkgs []string) (*depTree, error) {
} }
if len(dt.ToProcess) > 0 { if len(dt.ToProcess) > 0 {
fmt.Println(bold(cyan("::") + " Querying AUR...")) fmt.Println(bold(cyan("::") + bold(" Querying AUR...")))
} }
err = depTreeRecursive(dt, localDb, syncDb, false) err = depTreeRecursive(dt, localDb, syncDb, false)
@ -394,6 +397,8 @@ func getDepTree(pkgs []string) (*depTree, error) {
err = checkVersions(dt) err = checkVersions(dt)
} }
dt.Warnings.Print()
return dt, err return dt, err
} }
@ -456,7 +461,7 @@ func depTreeRecursive(dt *depTree, localDb *alpm.Db, syncDb alpm.DbList, isMake
} }
// Assume toprocess only contains aur stuff we have not seen // Assume toprocess only contains aur stuff we have not seen
info, err := aurInfo(currentProcess.toSlice()) info, err := aurInfo(currentProcess.toSlice(), dt.Warnings)
if err != nil { if err != nil {
return return

View File

@ -107,10 +107,10 @@ nextPkg:
errD := downloadAndUnpack(url, path, true) errD := downloadAndUnpack(url, path, true)
if errD != nil { if errD != nil {
fmt.Println(bold(magenta(pkg.Name())), bold(green(errD.Error()))) fmt.Println(bold(red(arrow)) + " " + bold(cyan(pkg.Name())), bold(red(errD.Error())))
} }
fmt.Println(bold(green(arrow)), bold(green("Downloaded")), bold(magenta(pkg.Name())), bold(green("from ABS"))) fmt.Println(bold(yellow(arrow)), "Downloaded", cyan(pkg.Name()), "from ABS")
continue nextPkg continue nextPkg
} }
} }
@ -123,14 +123,14 @@ nextPkg:
// GetPkgbuild downloads pkgbuild from the AUR. // GetPkgbuild downloads pkgbuild from the AUR.
func getPkgbuildsfromAUR(pkgs []string, dir string) (err error) { func getPkgbuildsfromAUR(pkgs []string, dir string) (err error) {
aq, err := aurInfo(pkgs) aq, err := aurInfoPrint(pkgs)
if err != nil { if err != nil {
return err return err
} }
for _, pkg := range aq { for _, pkg := range aq {
downloadAndUnpack(baseURL+aq[0].URLPath, dir, false) downloadAndUnpack(baseURL+aq[0].URLPath, dir, false)
fmt.Println(bold(green(arrow)), bold(green("Downloaded")), bold(magenta(pkg.Name)), bold(green("from AUR"))) fmt.Println(bold(yellow(arrow)), "Downloaded", cyan(pkg.Name), "from AUR")
} }
return return

View File

@ -24,6 +24,8 @@ func install(parser *arguments) error {
var aurUp upSlice var aurUp upSlice
var repoUp upSlice var repoUp upSlice
warnings := &aurWarnings{}
removeMake := false removeMake := false
srcinfosStale := make(map[string]*gopkg.PKGBUILD) srcinfosStale := make(map[string]*gopkg.PKGBUILD)
srcinfos := make(map[string]*gopkg.PKGBUILD) srcinfos := make(map[string]*gopkg.PKGBUILD)
@ -41,7 +43,7 @@ func install(parser *arguments) error {
//if we are doing -u also request all packages needing update //if we are doing -u also request all packages needing update
if parser.existsArg("u", "sysupgrade") { if parser.existsArg("u", "sysupgrade") {
aurUp, repoUp, err = upList() aurUp, repoUp, err = upList(warnings)
if err != nil { if err != nil {
return err return err
} }
@ -59,7 +61,7 @@ func install(parser *arguments) error {
//if len(aurTargets) > 0 || parser.existsArg("u", "sysupgrade") && len(remoteNames) > 0 { //if len(aurTargets) > 0 || parser.existsArg("u", "sysupgrade") && len(remoteNames) > 0 {
// fmt.Println(bold(cyan("::") + " Querying AUR...")) // fmt.Println(bold(cyan("::") + " Querying AUR..."))
//} //}
dt, err := getDepTree(requestTargets) dt, err := getDepTree(requestTargets, warnings)
if err != nil { if err != nil {
return err return err
} }
@ -81,7 +83,7 @@ func install(parser *arguments) error {
str := bold(red(arrow+" Error: ")) + "Could not find all required packages:" str := bold(red(arrow+" Error: ")) + "Could not find all required packages:"
for name := range dt.Missing { for name := range dt.Missing {
str += "\n\t" + name str += "\n " + name
} }
return fmt.Errorf("%s", str) return fmt.Errorf("%s", str)
@ -129,7 +131,7 @@ func install(parser *arguments) error {
} }
if hasAur && 0 == os.Geteuid() { if hasAur && 0 == os.Geteuid() {
return fmt.Errorf(red(arrow + " Refusing to install AUR Packages as root, Aborting.")) return fmt.Errorf(bold(red(arrow)) + " Refusing to install AUR Packages as root, Aborting.")
} }
dc, err = getDepCatagories(requestTargets, dt) dc, err = getDepCatagories(requestTargets, dt)
@ -151,15 +153,16 @@ func install(parser *arguments) error {
} }
if hasAur { if hasAur {
printDepCatagories(dc)
hasAur = len(dc.Aur) != 0 hasAur = len(dc.Aur) != 0
fmt.Println()
err = checkForAllConflicts(dc) err = checkForAllConflicts(dc)
if err != nil { if err != nil {
return err return err
} }
printDepCatagories(dc)
fmt.Println()
if len(dc.MakeOnly) > 0 { if len(dc.MakeOnly) > 0 {
if !continueTask("Remove make dependencies after install?", "yY") { if !continueTask("Remove make dependencies after install?", "yY") {
removeMake = true removeMake = true
@ -170,6 +173,7 @@ func install(parser *arguments) error {
if err != nil { if err != nil {
return err return err
} }
cleanBuilds(toClean) cleanBuilds(toClean)
err = downloadPkgBuilds(dc.Aur, parser.targets, dc.Bases) err = downloadPkgBuilds(dc.Aur, parser.targets, dc.Bases)
@ -182,6 +186,13 @@ func install(parser *arguments) error {
if err != nil { if err != nil {
return err return err
} }
oldValue := config.NoConfirm
config.NoConfirm = false
if !continueTask(bold(green("Proceed with install?")), "nN") {
return fmt.Errorf("Aborting due to user")
}
config.NoConfirm = oldValue
} }
//inital srcinfo parse before pkgver() bump //inital srcinfo parse before pkgver() bump
@ -222,13 +233,6 @@ func install(parser *arguments) error {
return fmt.Errorf("%s%s", stderr, err) return fmt.Errorf("%s%s", stderr, err)
} }
} }
} else if hasAur {
oldValue := config.NoConfirm
config.NoConfirm = false
if len(toEdit) > 0 && !continueTask("Proceed with install?", "nN") {
return fmt.Errorf("Aborting due to user")
}
config.NoConfirm = oldValue
} }
if hasAur { if hasAur {
@ -303,8 +307,8 @@ nextpkg:
} }
if len(incompatible) > 0 { if len(incompatible) > 0 {
fmt.Print( fmt.Println()
bold(green(("\nThe following packages are not compatable with your architecture:")))) fmt.Print(bold(yellow(arrow)) + " The following packages are not compatable with your architecture:")
for pkg := range incompatible { for pkg := range incompatible {
fmt.Print(" " + cyan(pkg)) fmt.Print(" " + cyan(pkg))
} }
@ -329,7 +333,7 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
for n, pkg := range pkgs { for n, pkg := range pkgs {
dir := config.BuildDir + pkg.PackageBase + "/" dir := config.BuildDir + pkg.PackageBase + "/"
toPrint += fmt.Sprintf("%s %-40s", magenta(strconv.Itoa(len(pkgs)-n)), toPrint += fmt.Sprintf(magenta("%3d")+" %-40s", len(pkgs)-n,
bold(formatPkgbase(pkg, bases))) bold(formatPkgbase(pkg, bases)))
if installed.get(pkg.Name) { if installed.get(pkg.Name) {
toPrint += bold(green(" (Installed)")) toPrint += bold(green(" (Installed)"))
@ -345,9 +349,10 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
fmt.Print(toPrint) fmt.Print(toPrint)
if askClean { if askClean {
fmt.Println(bold(green(arrow + " Packages to cleanBuild?"))) fmt.Println(bold(green(arrow + " Packages to cleanBuild?")))
fmt.Println(bold(green(arrow) + cyan(" [N]one ") + green("[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)"))) fmt.Println(bold(green(arrow) + cyan(" [N]one ") + "[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)"))
fmt.Print(bold(green(arrow + " "))) fmt.Print(bold(green(arrow + " ")))
cleanInput, err := getInput(config.AnswerClean) cleanInput, err := getInput(config.AnswerClean)
if err != nil { if err != nil {
@ -401,7 +406,7 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
} }
fmt.Println(bold(green(arrow + " PKGBUILDs to edit?"))) fmt.Println(bold(green(arrow + " PKGBUILDs to edit?")))
fmt.Println(bold(green(arrow) + cyan(" [N]one ") + green("[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)"))) fmt.Println(bold(green(arrow) + cyan(" [N]one ") + "[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)"))
fmt.Print(bold(green(arrow + " "))) fmt.Print(bold(green(arrow + " ")))
@ -454,7 +459,7 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
func cleanBuilds(pkgs []*rpc.Pkg) { func cleanBuilds(pkgs []*rpc.Pkg) {
for i, pkg := range pkgs { for i, pkg := range pkgs {
dir := config.BuildDir + pkg.PackageBase dir := config.BuildDir + pkg.PackageBase
fmt.Printf(bold(cyan("::")+" Deleting (%d/%d): %s\n"), i+1, len(pkgs), dir) fmt.Printf(bold(cyan("::")+" Deleting (%d/%d): %s\n"), i+1, len(pkgs), cyan(dir))
os.RemoveAll(dir) os.RemoveAll(dir)
} }
} }
@ -483,7 +488,7 @@ func parseSRCINFOFiles(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD, bas
dir := config.BuildDir + pkg.PackageBase + "/" dir := config.BuildDir + pkg.PackageBase + "/"
str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n") str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n")
fmt.Printf(str, k+1, len(pkgs), formatPkgbase(pkg, bases)) fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))
pkgbuild, err := gopkg.ParseSRCINFO(dir + ".SRCINFO") pkgbuild, err := gopkg.ParseSRCINFO(dir + ".SRCINFO")
if err != nil { if err != nil {
@ -501,7 +506,7 @@ func tryParsesrcinfosFile(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD,
dir := config.BuildDir + pkg.PackageBase + "/" dir := config.BuildDir + pkg.PackageBase + "/"
str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n") str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n")
fmt.Printf(str, k+1, len(pkgs), formatPkgbase(pkg, bases)) fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))
pkgbuild, err := gopkg.ParseSRCINFO(dir + ".SRCINFO") pkgbuild, err := gopkg.ParseSRCINFO(dir + ".SRCINFO")
if err != nil { if err != nil {
@ -551,7 +556,7 @@ func downloadPkgBuilds(pkgs []*rpc.Pkg, targets stringSet, bases map[string][]*r
if err == nil { if err == nil {
if !version.Newer(pkgbuild.Version()) { if !version.Newer(pkgbuild.Version()) {
str := bold(cyan("::") + " PKGBUILD up to date, Skipping (%d/%d): %s\n") str := bold(cyan("::") + " PKGBUILD up to date, Skipping (%d/%d): %s\n")
fmt.Printf(str, k+1, len(pkgs), formatPkgbase(pkg, bases)) fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))
continue continue
} }
} }
@ -560,7 +565,7 @@ func downloadPkgBuilds(pkgs []*rpc.Pkg, targets stringSet, bases map[string][]*r
str := bold(cyan("::") + " Downloading PKGBUILD (%d/%d): %s\n") str := bold(cyan("::") + " Downloading PKGBUILD (%d/%d): %s\n")
fmt.Printf(str, k+1, len(pkgs), formatPkgbase(pkg, bases)) fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))
err := downloadAndUnpack(baseURL+pkg.URLPath, config.BuildDir, false) err := downloadAndUnpack(baseURL+pkg.URLPath, config.BuildDir, false)
if err != nil { if err != nil {
@ -582,7 +587,7 @@ func downloadPkgBuildsSources(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, inco
err = passToMakepkg(dir, args...) err = passToMakepkg(dir, args...)
if err != nil { if err != nil {
return fmt.Errorf("Error downloading sources: %s", formatPkgbase(pkg, bases)) return fmt.Errorf("Error downloading sources: %s", cyan(formatPkgbase(pkg, bases)))
} }
} }
@ -625,8 +630,8 @@ func buildInstallPkgBuilds(pkgs []*rpc.Pkg, srcinfos map[string]*gopkg.PKGBUILD,
} }
if built { if built {
fmt.Println(bold(red(arrow+" Warning:")), fmt.Println(bold(yellow(arrow)),
pkg.Name+"-"+pkg.Version+" Already made -- skipping build") cyan(pkg.Name+"-"+pkg.Version) + bold(" Already made -- skipping build"))
} else { } else {
args := []string{"-Ccf", "--noconfirm"} args := []string{"-Ccf", "--noconfirm"}

18
keys.go
View File

@ -72,12 +72,16 @@ func checkPgpKeys(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, srcinfos map[str
return nil return nil
} }
fmt.Println() str, err := formatKeysToImport(problematic, bases)
question, err := formatKeysToImport(problematic, bases)
if err != nil { if err != nil {
return err return err
} }
if continueTask(question, "nN") {
fmt.Println()
fmt.Println(str)
if continueTask(bold(green("Import?")), "nN") {
return importKeys(problematic.toSlice()) return importKeys(problematic.toSlice())
} }
@ -90,7 +94,7 @@ func importKeys(keys []string) error {
cmd := exec.Command(config.GpgBin, append(args, keys...)...) cmd := exec.Command(config.GpgBin, append(args, keys...)...)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
fmt.Printf("%s Importing keys with gpg...\n", bold(cyan("::"))) fmt.Printf("%s %s...\n", bold(cyan("::")), bold("Importing keys with gpg..."))
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
@ -107,15 +111,15 @@ func formatKeysToImport(keys pgpKeySet, bases map[string][]*rpc.Pkg) (string, er
} }
var buffer bytes.Buffer var buffer bytes.Buffer
buffer.WriteString(bold(green(("GPG keys need importing:\n")))) buffer.WriteString(bold(green(arrow)))
buffer.WriteString(bold(green(" PGP keys need importing:")))
for key, pkgs := range keys { for key, pkgs := range keys {
pkglist := "" pkglist := ""
for _, pkg := range pkgs { for _, pkg := range pkgs {
pkglist += formatPkgbase(pkg, bases) + " " pkglist += formatPkgbase(pkg, bases) + " "
} }
pkglist = strings.TrimRight(pkglist, " ") pkglist = strings.TrimRight(pkglist, " ")
buffer.WriteString(fmt.Sprintf("\t%s, required by: %s\n", green(key), cyan(pkglist))) buffer.WriteString(fmt.Sprintf("\n%s %s, required by: %s", yellow(bold(smallArrow)), cyan(key), cyan(pkglist)))
} }
buffer.WriteString(bold(green(fmt.Sprintf("%s Import?", arrow))))
return buffer.String(), nil return buffer.String(), nil
} }

View File

@ -11,6 +11,34 @@ import (
) )
const arrow = "==>" const arrow = "==>"
const smallArrow = " ->"
func (warnings *aurWarnings) Print() {
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()
}
}
// human method returns results in human readable format. // human method returns results in human readable format.
func human(size int64) string { func human(size int64) string {
@ -131,7 +159,7 @@ func (u upSlice) Print(start int) {
left, right := getVersionDiff(i.LocalVersion, i.RemoteVersion) left, right := getVersionDiff(i.LocalVersion, i.RemoteVersion)
fmt.Print(magenta(fmt.Sprintf("%3d ", len(u)+start-k-1))) fmt.Print(magenta(fmt.Sprintf("%3d ", len(u)+start-k-1)))
fmt.Print(bold(colourHash(i.Repository)), "/", cyan(i.Name)) fmt.Print(bold(colourHash(i.Repository)), "/", bold(i.Name))
w := 70 - len(i.Repository) - len(i.Name) w := 70 - len(i.Repository) - len(i.Name)
padding := fmt.Sprintf("%%%ds", w) padding := fmt.Sprintf("%%%ds", w)
@ -216,7 +244,7 @@ func printDownloads(repoName string, length int, packages string) {
repoInfo := bold(blue( repoInfo := bold(blue(
"[" + repoName + ": " + strconv.Itoa(length) + "]")) "[" + repoName + ": " + strconv.Itoa(length) + "]"))
fmt.Println(repoInfo + magenta(packages)) fmt.Println(repoInfo + cyan(packages))
} }
// PrintInfo prints package info like pacman -Si. // PrintInfo prints package info like pacman -Si.
@ -277,16 +305,16 @@ func localStatistics() error {
fmt.Printf(bold("Yay version v%s\n"), version) fmt.Printf(bold("Yay version v%s\n"), version)
fmt.Println(bold(cyan("==========================================="))) fmt.Println(bold(cyan("===========================================")))
fmt.Println(bold(green("Total installed packages: ")) + magenta(strconv.Itoa(info.Totaln))) fmt.Println(bold(green("Total installed packages: ")) + cyan(strconv.Itoa(info.Totaln)))
fmt.Println(bold(green("Total foreign installed packages: ")) + magenta(strconv.Itoa(len(remoteNames)))) fmt.Println(bold(green("Total foreign installed packages: ")) + cyan(strconv.Itoa(len(remoteNames))))
fmt.Println(bold(green("Explicitly installed packages: ")) + magenta(strconv.Itoa(info.Expln))) fmt.Println(bold(green("Explicitly installed packages: ")) + cyan(strconv.Itoa(info.Expln)))
fmt.Println(bold(green("Total Size occupied by packages: ")) + magenta(human(info.TotalSize))) fmt.Println(bold(green("Total Size occupied by packages: ")) + cyan(human(info.TotalSize)))
fmt.Println(bold(cyan("==========================================="))) fmt.Println(bold(cyan("===========================================")))
fmt.Println(bold(green("Ten biggest packages:"))) fmt.Println(bold(green("Ten biggest packages:")))
biggestPackages() biggestPackages()
fmt.Println(bold(cyan("==========================================="))) fmt.Println(bold(cyan("===========================================")))
aurInfo(remoteNames) aurInfoPrint(remoteNames)
return nil return nil
} }
@ -294,9 +322,10 @@ func localStatistics() error {
//TODO: Make it less hacky //TODO: Make it less hacky
func printNumberOfUpdates() error { func printNumberOfUpdates() error {
//todo //todo
warnings := &aurWarnings{}
old := os.Stdout // keep backup of the real stdout old := os.Stdout // keep backup of the real stdout
os.Stdout = nil os.Stdout = nil
aurUp, repoUp, err := upList() aurUp, repoUp, err := upList(warnings)
os.Stdout = old // restoring the real stdout os.Stdout = old // restoring the real stdout
if err != nil { if err != nil {
return err return err
@ -308,10 +337,11 @@ func printNumberOfUpdates() error {
//TODO: Make it less hacky //TODO: Make it less hacky
func printUpdateList(parser *arguments) error { func printUpdateList(parser *arguments) error {
warnings := &aurWarnings{}
old := os.Stdout // keep backup of the real stdout old := os.Stdout // keep backup of the real stdout
os.Stdout = nil os.Stdout = nil
_, _, localNames, remoteNames, err := filterPackages() _, _, localNames, remoteNames, err := filterPackages()
aurUp, repoUp, err := upList() aurUp, repoUp, err := upList(warnings)
os.Stdout = old // restoring the real stdout os.Stdout = old // restoring the real stdout
if err != nil { if err != nil {
return err return err

View File

@ -10,6 +10,12 @@ import (
rpc "github.com/mikkeloscar/aur" rpc "github.com/mikkeloscar/aur"
) )
type aurWarnings struct {
Orphans []string
OutOfDate []string
Missing []string
}
// Query is a collection of Results // Query is a collection of Results
type aurQuery []rpc.Pkg type aurQuery []rpc.Pkg
@ -190,7 +196,7 @@ func syncInfo(pkgS []string) (err error) {
noDb = append(noDb, name) noDb = append(noDb, name)
} }
info, err = aurInfo(noDb) info, err = aurInfoPrint(noDb)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
@ -440,17 +446,13 @@ func statistics() (info struct {
// of packages exceeds the number set in config.RequestSplitN. // of packages exceeds the number set in config.RequestSplitN.
// If the number does exceed config.RequestSplitN multiple rpc requests will be // If the number does exceed config.RequestSplitN multiple rpc requests will be
// performed concurrently. // performed concurrently.
func aurInfo(names []string) ([]*rpc.Pkg, error) { func aurInfo(names []string, warnings *aurWarnings) ([]*rpc.Pkg, error) {
info := make([]*rpc.Pkg, 0, len(names)) info := make([]*rpc.Pkg, 0, len(names))
seen := make(map[string]int) seen := make(map[string]int)
var mux sync.Mutex var mux sync.Mutex
var wg sync.WaitGroup var wg sync.WaitGroup
var err error var err error
missing := make([]string, 0, len(names))
orphans := make([]string, 0, len(names))
outOfDate := make([]string, 0, len(names))
makeRequest := func(n, max int) { makeRequest := func(n, max int) {
defer wg.Done() defer wg.Done()
tempInfo, requestErr := rpc.Info(names[n:max]) tempInfo, requestErr := rpc.Info(names[n:max])
@ -488,43 +490,33 @@ func aurInfo(names []string) ([]*rpc.Pkg, error) {
for _, name := range names { for _, name := range names {
i, ok := seen[name] i, ok := seen[name]
if !ok { if !ok {
missing = append(missing, name) warnings.Missing = append(warnings.Missing, name)
continue continue
} }
pkg := info[i] pkg := info[i]
if pkg.Maintainer == "" { if pkg.Maintainer == "" {
orphans = append(orphans, name) warnings.Orphans = append(warnings.Orphans, name)
} }
if pkg.OutOfDate != 0 { if pkg.OutOfDate != 0 {
outOfDate = append(outOfDate, name) warnings.OutOfDate = append(warnings.OutOfDate, name)
} }
} }
if len(missing) > 0 { return info, nil
fmt.Print(bold(red(arrow + " Missing AUR Packages:"))) }
for _, name := range missing {
fmt.Print(" " + bold(magenta(name))) func aurInfoPrint(names []string) ([]*rpc.Pkg, error) {
} fmt.Println(bold(cyan("::") + bold(" Querying AUR...")))
fmt.Println()
} warnings := &aurWarnings{}
info, err := aurInfo(names, warnings)
if len(orphans) > 0 { if err != nil {
fmt.Print(bold(red(arrow + " Orphaned AUR Packages:"))) return info, err
for _, name := range orphans { }
fmt.Print(" " + bold(magenta(name)))
} warnings.Print()
fmt.Println()
}
if len(outOfDate) > 0 {
fmt.Print(bold(red(arrow + " Out Of Date AUR Packages:")))
for _, name := range outOfDate {
fmt.Print(" " + bold(magenta(name)))
}
fmt.Println()
}
return info, nil return info, nil
} }

View File

@ -125,7 +125,7 @@ func getVersionDiff(oldVersion, newversion string) (left, right string) {
} }
// upList returns lists of packages to upgrade from each source. // upList returns lists of packages to upgrade from each source.
func upList() (aurUp upSlice, repoUp upSlice, err error) { func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) {
local, remote, _, remoteNames, err := filterPackages() local, remote, _, remoteNames, err := filterPackages()
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -138,22 +138,22 @@ func upList() (aurUp upSlice, repoUp upSlice, err error) {
var aurErr error var aurErr error
var develErr error var develErr error
fmt.Println(bold(cyan("::") + " Searching databases for updates...")) fmt.Println(bold(cyan("::") + bold(" Searching databases for updates...")))
wg.Add(1) wg.Add(1)
go func() { go func() {
repoUp, repoErr = upRepo(local) repoUp, repoErr = upRepo(local)
wg.Done() wg.Done()
}() }()
fmt.Println(bold(cyan("::") + " Searching AUR for updates...")) fmt.Println(bold(cyan("::") + bold(" Searching AUR for updates...")))
wg.Add(1) wg.Add(1)
go func() { go func() {
aurUp, aurErr = upAUR(remote, remoteNames) aurUp, aurErr = upAUR(remote, remoteNames, warnings)
wg.Done() wg.Done()
}() }()
if config.Devel { if config.Devel {
fmt.Println(bold(cyan("::") + " Checking development packages...")) fmt.Println(bold(cyan("::") + bold(" Checking development packages...")))
wg.Add(1) wg.Add(1)
go func() { go func() {
develUp, develErr = upDevel(remote) develUp, develErr = upDevel(remote)
@ -229,8 +229,8 @@ func upDevel(remote []alpm.Package) (toUpgrade upSlice, err error) {
for _, pkg := range toUpdate { for _, pkg := range toUpdate {
if pkg.ShouldIgnore() { if pkg.ShouldIgnore() {
left, right := getVersionDiff(pkg.Version(), "latest-commit") left, right := getVersionDiff(pkg.Version(), "latest-commit")
fmt.Print(magenta("Warning: ")) fmt.Print(yellow(bold(smallArrow)))
fmt.Printf("%s ignoring package upgrade (%s => %s)\n", cyan(pkg.Name()), left, right) fmt.Printf(" Ignoring package upgrade %s (%s => %s)\n", cyan(pkg.Name()), left, right)
} else { } else {
toUpgrade = append(toUpgrade, upgrade{pkg.Name(), "devel", pkg.Version(), "latest-commit"}) toUpgrade = append(toUpgrade, upgrade{pkg.Name(), "devel", pkg.Version(), "latest-commit"})
} }
@ -242,9 +242,9 @@ func upDevel(remote []alpm.Package) (toUpgrade upSlice, err error) {
// upAUR gathers foreign packages and checks if they have new versions. // upAUR gathers foreign packages and checks if they have new versions.
// Output: Upgrade type package list. // Output: Upgrade type package list.
func upAUR(remote []alpm.Package, remoteNames []string) (upSlice, error) { func upAUR(remote []alpm.Package, remoteNames []string, warnings *aurWarnings) (upSlice, error) {
toUpgrade := make(upSlice, 0) toUpgrade := make(upSlice, 0)
_pkgdata, err := aurInfo(remoteNames) _pkgdata, err := aurInfo(remoteNames, warnings)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -264,8 +264,8 @@ func upAUR(remote []alpm.Package, remoteNames []string) (upSlice, error) {
(alpm.VerCmp(pkg.Version(), aurPkg.Version) < 0) { (alpm.VerCmp(pkg.Version(), aurPkg.Version) < 0) {
if pkg.ShouldIgnore() { if pkg.ShouldIgnore() {
left, right := getVersionDiff(pkg.Version(), aurPkg.Version) left, right := getVersionDiff(pkg.Version(), aurPkg.Version)
fmt.Print(magenta("Warning: ")) fmt.Print(yellow(bold(smallArrow)))
fmt.Printf("%s ignoring package upgrade (%s => %s)\n", cyan(pkg.Name()), left, right) fmt.Printf(" Ignoring package upgrade: %s (%s => %s)\n", cyan(pkg.Name()), left, right)
} else { } else {
toUpgrade = append(toUpgrade, upgrade{aurPkg.Name, "aur", pkg.Version(), aurPkg.Version}) toUpgrade = append(toUpgrade, upgrade{aurPkg.Name, "aur", pkg.Version(), aurPkg.Version})
} }
@ -290,8 +290,8 @@ func upRepo(local []alpm.Package) (upSlice, error) {
if newPkg != nil { if newPkg != nil {
if pkg.ShouldIgnore() { if pkg.ShouldIgnore() {
left, right := getVersionDiff(pkg.Version(), newPkg.Version()) left, right := getVersionDiff(pkg.Version(), newPkg.Version())
fmt.Print(magenta("Warning: ")) fmt.Print(yellow(bold(smallArrow)))
fmt.Printf("%s ignoring package upgrade (%s => %s)\n", cyan(pkg.Name()), left, right) fmt.Printf(" Ignoring package upgrade: %s (%s => %s)\n", cyan(pkg.Name()), left, right)
} else { } else {
slice = append(slice, upgrade{pkg.Name(), newPkg.DB().Name(), pkg.Version(), newPkg.Version()}) slice = append(slice, upgrade{pkg.Name(), newPkg.DB().Name(), pkg.Version(), newPkg.Version()})
} }
@ -311,11 +311,11 @@ func upgradePkgs(aurUp, repoUp upSlice) (stringSet, stringSet, error) {
sort.Sort(repoUp) sort.Sort(repoUp)
sort.Sort(aurUp) sort.Sort(aurUp)
fmt.Println(bold(blue("::")), len(aurUp)+len(repoUp), bold("Packages to upgrade.")) fmt.Printf("%s"+bold(" %d ")+"%s\n", bold(cyan("::")), len(aurUp)+len(repoUp), bold("Packages to upgrade."))
repoUp.Print(len(aurUp) + 1) repoUp.Print(len(aurUp) + 1)
aurUp.Print(1) aurUp.Print(1)
fmt.Println(bold(green(arrow + " Packages to not upgrade (eg: 1 2 3, 1-3, ^4 or repo name)"))) fmt.Println(bold(green(arrow + " Packages to not upgrade: (eg: 1 2 3, 1-3, ^4 or repo name)")))
fmt.Print(bold(green(arrow + " "))) fmt.Print(bold(green(arrow + " ")))
numbers, err := getInput(config.AnswerUpgrade) numbers, err := getInput(config.AnswerUpgrade)

6
vcs.go
View File

@ -32,7 +32,7 @@ func createDevelDB() error {
return err return err
} }
info, err := aurInfo(remoteNames) info, err := aurInfoPrint(remoteNames)
if err != nil { if err != nil {
return err return err
} }
@ -57,7 +57,7 @@ func createDevelDB() error {
} }
} }
fmt.Println(bold(green(arrow + " GenDB finished. No packages were installed"))) fmt.Println(bold(yellow(arrow) + bold(" GenDB finished. No packages were installed")))
return err return err
} }
@ -125,7 +125,7 @@ func updateVCSData(pkgName string, sources []string) {
savedInfo[pkgName] = info savedInfo[pkgName] = info
fmt.Println(bold(green(arrow+" Found git repo: ")) + cyan(url)) fmt.Println(bold(yellow(arrow)) + " Found git repo: " + cyan(url))
saveVCSInfo() saveVCSInfo()
} }
} }