From 06406d7cee33f5679f02e5d0c4d9ddd2028ca3e5 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Wed, 11 Apr 2018 04:43:51 +0100 Subject: [PATCH] More formatting tweaks Ensure aurWarnings will always be printed out in one block use '->' for printing aur warnings and ignored upgrades use '->' for conflict printing use '->' for key importing Say PGP keys not GPG keys Add back green for input prompts Use 4 spcaces over \t --- callbacks.go | 2 +- config.go | 6 ++--- conflicts.go | 15 +++++++------ dependencies.go | 9 ++++++-- download.go | 2 +- install.go | 23 +++++++++++++++----- keys.go | 18 +++++++++------ print.go | 36 +++++++++++++++++++++++++++--- query.go | 58 +++++++++++++++++++++---------------------------- upgrade.go | 22 +++++++++---------- vcs.go | 2 +- 11 files changed, 118 insertions(+), 75 deletions(-) diff --git a/callbacks.go b/callbacks.go index 5bdaef02..e0b147a8 100644 --- a/callbacks.go +++ b/callbacks.go @@ -34,7 +34,7 @@ func questionCallback(question alpm.QuestionAny) { if 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()) size++ diff --git a/config.go b/config.go index 86310b86..ecc7ab66 100644 --- a/config.go +++ b/config.go @@ -187,11 +187,11 @@ func editor() (string, []string) { fallthrough default: fmt.Println() - fmt.Println(bold(red(arrow)), cyan("$EDITOR"), "is not set") - fmt.Println(bold(red(arrow)) + " Please add " + cyan("$EDITOR") + " or " + cyan("$VISUAL") + " to your environment variables.") + fmt.Println(bold(red(arrow)), bold(cyan("$EDITOR")), bold("is not set")) + fmt.Println(bold(red(arrow)) + bold(" Please add ") + bold(cyan("$EDITOR")) + bold(" or ") + bold(cyan("$VISUAL")) + bold(" to your environment variables.")) for { - fmt.Print(green(bold(arrow)) + " Edit PKGBUILD with: ") + fmt.Print(green(bold(arrow + " Edit PKGBUILD with: "))) editorInput, err := getInput("") if err != nil { fmt.Println(err) diff --git a/conflicts.go b/conflicts.go index d26169aa..759de489 100644 --- a/conflicts.go +++ b/conflicts.go @@ -320,10 +320,11 @@ func checkForAllConflicts(dc *depCatagories) error { } if len(innerConflicts) != 0 { - fmt.Println( - red("\nInner conflicts found:")) + fmt.Println() + fmt.Println(bold(red(arrow)), bold("Inner conflicts found:")) + for name, pkgs := range innerConflicts { - str := "\t" + name + ":" + str := red(bold(smallArrow)) + " " + name + ":" for pkg := range pkgs { str += " " + cyan(pkg) } @@ -331,14 +332,14 @@ func checkForAllConflicts(dc *depCatagories) error { fmt.Println(str) } - return fmt.Errorf("Aborting") + return fmt.Errorf("Unresolvable package conflicts, aborting") } if len(conflicts) != 0 { - fmt.Println( - red("\nPackage conflicts found:")) + fmt.Println() + fmt.Println(bold(red(arrow)), bold("Package conflicts found:")) for name, pkgs := range conflicts { - str := "\tInstalling " + cyan(name) + " will remove:" + str := red(bold(smallArrow)) + " Installing " + cyan(name) + " will remove:" for pkg := range pkgs { str += " " + cyan(pkg) } diff --git a/dependencies.go b/dependencies.go index c74fd2e6..c19dd26f 100644 --- a/dependencies.go +++ b/dependencies.go @@ -16,6 +16,7 @@ type depTree struct { Missing stringSet Groups stringSet Provides map[string]string + Warnings *aurWarnings } type depCatagories struct { @@ -33,6 +34,7 @@ func makeDepTree() *depTree { make(stringSet), make(stringSet), make(map[string]string), + &aurWarnings{}, } 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 example does not really do this justice, In the real world where packages // 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.Warnings = warnings localDb, err := alpmHandle.LocalDb() if err != nil { @@ -394,6 +397,8 @@ func getDepTree(pkgs []string) (*depTree, error) { err = checkVersions(dt) } + dt.Warnings.Print() + 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 - info, err := aurInfo(currentProcess.toSlice()) + info, err := aurInfo(currentProcess.toSlice(), dt.Warnings) if err != nil { return diff --git a/download.go b/download.go index d4e6bacc..98b5ecf7 100644 --- a/download.go +++ b/download.go @@ -123,7 +123,7 @@ nextPkg: // GetPkgbuild downloads pkgbuild from the AUR. func getPkgbuildsfromAUR(pkgs []string, dir string) (err error) { - aq, err := aurInfo(pkgs) + aq, err := aurInfoPrint(pkgs) if err != nil { return err } diff --git a/install.go b/install.go index ddb00c45..3018f5e5 100644 --- a/install.go +++ b/install.go @@ -24,6 +24,8 @@ func install(parser *arguments) error { var aurUp upSlice var repoUp upSlice + warnings := &aurWarnings{} + removeMake := false srcinfosStale := 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 parser.existsArg("u", "sysupgrade") { - aurUp, repoUp, err = upList() + aurUp, repoUp, err = upList(warnings) if err != nil { return err } @@ -59,7 +61,7 @@ func install(parser *arguments) error { //if len(aurTargets) > 0 || parser.existsArg("u", "sysupgrade") && len(remoteNames) > 0 { // fmt.Println(bold(cyan("::") + " Querying AUR...")) //} - dt, err := getDepTree(requestTargets) + dt, err := getDepTree(requestTargets, warnings) if err != nil { return err } @@ -81,7 +83,7 @@ func install(parser *arguments) error { str := bold(red(arrow+" Error: ")) + "Could not find all required packages:" for name := range dt.Missing { - str += "\n\t" + name + str += "\n " + name } return fmt.Errorf("%s", str) @@ -151,15 +153,16 @@ func install(parser *arguments) error { } if hasAur { - printDepCatagories(dc) hasAur = len(dc.Aur) != 0 - fmt.Println() err = checkForAllConflicts(dc) if err != nil { return err } + printDepCatagories(dc) + fmt.Println() + if len(dc.MakeOnly) > 0 { if !continueTask("Remove make dependencies after install?", "yY") { removeMake = true @@ -182,6 +185,13 @@ func install(parser *arguments) error { if err != nil { 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 @@ -329,7 +339,7 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed for n, pkg := range pkgs { 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))) if installed.get(pkg.Name) { toPrint += bold(green(" (Installed)")) @@ -345,6 +355,7 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed fmt.Print(toPrint) + if askClean { fmt.Println(bold(green(arrow + " Packages to cleanBuild?"))) fmt.Println(bold(green(arrow) + cyan(" [N]one ") + "[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)")) diff --git a/keys.go b/keys.go index 945e5e07..da9d519c 100644 --- a/keys.go +++ b/keys.go @@ -72,12 +72,16 @@ func checkPgpKeys(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, srcinfos map[str return nil } - fmt.Println() - question, err := formatKeysToImport(problematic, bases) + str, err := formatKeysToImport(problematic, bases) if err != nil { return err } - if continueTask(question, "nN") { + + + fmt.Println() + fmt.Println(str) + + if continueTask(bold(green("Import?")), "nN") { return importKeys(problematic.toSlice()) } @@ -90,7 +94,7 @@ func importKeys(keys []string) error { cmd := exec.Command(config.GpgBin, append(args, keys...)...) 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() if err != nil { @@ -107,15 +111,15 @@ func formatKeysToImport(keys pgpKeySet, bases map[string][]*rpc.Pkg) (string, er } 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 { pkglist := "" for _, pkg := range pkgs { pkglist += formatPkgbase(pkg, bases) + " " } 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 } diff --git a/print.go b/print.go index 06049092..bb2873a8 100644 --- a/print.go +++ b/print.go @@ -11,6 +11,34 @@ import ( ) 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. func human(size int64) string { @@ -286,7 +314,7 @@ func localStatistics() error { biggestPackages() fmt.Println(bold(cyan("==========================================="))) - aurInfo(remoteNames) + aurInfoPrint(remoteNames) return nil } @@ -294,9 +322,10 @@ func localStatistics() error { //TODO: Make it less hacky func printNumberOfUpdates() error { //todo + warnings := &aurWarnings{} old := os.Stdout // keep backup of the real stdout os.Stdout = nil - aurUp, repoUp, err := upList() + aurUp, repoUp, err := upList(warnings) os.Stdout = old // restoring the real stdout if err != nil { return err @@ -308,10 +337,11 @@ func printNumberOfUpdates() error { //TODO: Make it less hacky func printUpdateList(parser *arguments) error { + warnings := &aurWarnings{} old := os.Stdout // keep backup of the real stdout os.Stdout = nil _, _, localNames, remoteNames, err := filterPackages() - aurUp, repoUp, err := upList() + aurUp, repoUp, err := upList(warnings) os.Stdout = old // restoring the real stdout if err != nil { return err diff --git a/query.go b/query.go index 2ac10f9a..99dcfe20 100644 --- a/query.go +++ b/query.go @@ -10,6 +10,12 @@ import ( rpc "github.com/mikkeloscar/aur" ) +type aurWarnings struct { + Orphans []string + OutOfDate []string + Missing []string +} + // Query is a collection of Results type aurQuery []rpc.Pkg @@ -190,7 +196,7 @@ func syncInfo(pkgS []string) (err error) { noDb = append(noDb, name) } - info, err = aurInfo(noDb) + info, err = aurInfoPrint(noDb) if err != nil { fmt.Println(err) } @@ -440,17 +446,13 @@ func statistics() (info struct { // of packages exceeds the number set in config.RequestSplitN. // If the number does exceed config.RequestSplitN multiple rpc requests will be // 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)) seen := make(map[string]int) var mux sync.Mutex var wg sync.WaitGroup 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) { defer wg.Done() tempInfo, requestErr := rpc.Info(names[n:max]) @@ -488,43 +490,33 @@ func aurInfo(names []string) ([]*rpc.Pkg, error) { for _, name := range names { i, ok := seen[name] if !ok { - missing = append(missing, name) + warnings.Missing = append(warnings.Missing, name) continue } pkg := info[i] if pkg.Maintainer == "" { - orphans = append(orphans, name) + warnings.Orphans = append(warnings.Orphans, name) } if pkg.OutOfDate != 0 { - outOfDate = append(outOfDate, name) + warnings.OutOfDate = append(warnings.OutOfDate, name) } } - if len(missing) > 0 { - fmt.Print(bold(yellow("==> ")) + "Missing AUR Packages:") - for _, name := range missing { - fmt.Print(" " + cyan(name)) - } - fmt.Println() - } - - if len(orphans) > 0 { - fmt.Print(bold(yellow("==> ")) + "Orphaned AUR Packages:") - for _, name := range orphans { - fmt.Print(" " + cyan(name)) - } - fmt.Println() - } - - if len(outOfDate) > 0 { - fmt.Print(bold(yellow("==> ")) + "Out Of Date AUR Packages:") - for _, name := range outOfDate { - fmt.Print(" " + cyan(name)) - } - fmt.Println() - } - + return info, nil +} + +func aurInfoPrint(names []string) ([]*rpc.Pkg, error) { + fmt.Println(bold(cyan("::") + bold(" Querying AUR..."))) + + warnings := &aurWarnings{} + info, err := aurInfo(names, warnings) + if err != nil { + return info, err + } + + warnings.Print() + return info, nil } diff --git a/upgrade.go b/upgrade.go index 8b47bc9e..c75b4504 100644 --- a/upgrade.go +++ b/upgrade.go @@ -125,7 +125,7 @@ func getVersionDiff(oldVersion, newversion string) (left, right string) { } // 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() if err != nil { return nil, nil, err @@ -148,7 +148,7 @@ func upList() (aurUp upSlice, repoUp upSlice, err error) { fmt.Println(bold(cyan("::") + bold(" Searching AUR for updates..."))) wg.Add(1) go func() { - aurUp, aurErr = upAUR(remote, remoteNames) + aurUp, aurErr = upAUR(remote, remoteNames, warnings) wg.Done() }() @@ -229,8 +229,8 @@ func upDevel(remote []alpm.Package) (toUpgrade upSlice, err error) { for _, pkg := range toUpdate { if pkg.ShouldIgnore() { left, right := getVersionDiff(pkg.Version(), "latest-commit") - fmt.Print(cyan("Warning: ")) - fmt.Printf("%s ignoring package upgrade (%s => %s)\n", cyan(pkg.Name()), left, right) + fmt.Print(yellow(bold(smallArrow))) + fmt.Printf(" Ignoring package upgrade %s (%s => %s)\n", cyan(pkg.Name()), left, right) } else { 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. // 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) - _pkgdata, err := aurInfo(remoteNames) + _pkgdata, err := aurInfo(remoteNames, warnings) if err != nil { return nil, err } @@ -264,8 +264,8 @@ func upAUR(remote []alpm.Package, remoteNames []string) (upSlice, error) { (alpm.VerCmp(pkg.Version(), aurPkg.Version) < 0) { if pkg.ShouldIgnore() { left, right := getVersionDiff(pkg.Version(), aurPkg.Version) - fmt.Print(cyan("Warning: ")) - fmt.Printf("%s ignoring package upgrade (%s => %s)\n", cyan(pkg.Name()), left, right) + fmt.Print(yellow(bold(smallArrow))) + fmt.Printf(" Ignoring package upgrade: %s (%s => %s)\n", cyan(pkg.Name()), left, right) } else { 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 pkg.ShouldIgnore() { left, right := getVersionDiff(pkg.Version(), newPkg.Version()) - fmt.Print(cyan("Warning: ")) - fmt.Printf("%s ignoring package upgrade (%s => %s)\n", cyan(pkg.Name()), left, right) + fmt.Print(yellow(bold(smallArrow))) + fmt.Printf(" Ignoring package upgrade: %s (%s => %s)\n", cyan(pkg.Name()), left, right) } else { slice = append(slice, upgrade{pkg.Name(), newPkg.DB().Name(), pkg.Version(), newPkg.Version()}) } @@ -315,7 +315,7 @@ func upgradePkgs(aurUp, repoUp upSlice) (stringSet, stringSet, error) { repoUp.Print(len(aurUp) + 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 + " "))) numbers, err := getInput(config.AnswerUpgrade) diff --git a/vcs.go b/vcs.go index a36b5cf1..c38dfcb1 100644 --- a/vcs.go +++ b/vcs.go @@ -32,7 +32,7 @@ func createDevelDB() error { return err } - info, err := aurInfo(remoteNames) + info, err := aurInfoPrint(remoteNames) if err != nil { return err }