Skip to content

Commit

Permalink
Simplify formatPkgBase
Browse files Browse the repository at this point in the history
Only pass the packages belonging to the desired pkgbase. Before our
entire list of every pkgbase had to be passed, as well as an example
package from the base we are looking for.

This lets use use formatPkgBase easier in other places outside of
install.

Many of the functions in install could also be simplified in a similar
way, although that has not been done in this commit.
  • Loading branch information
Morganamilo committed Aug 15, 2018
1 parent 0e40d9a commit 3dc350d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
16 changes: 8 additions & 8 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func install(parser *arguments) error {
}

for up := range aurUp {
requestTargets = append(requestTargets, "aur/" + up)
requestTargets = append(requestTargets, "aur/"+up)
parser.addTarget("aur/" + up)
}

Expand Down Expand Up @@ -493,7 +493,7 @@ func pkgbuildNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
dir := filepath.Join(config.BuildDir, pkg.PackageBase)

toPrint += fmt.Sprintf(magenta("%3d")+" %-40s", len(pkgs)-n,
bold(formatPkgbase(pkg, bases)))
bold(formatPkgbase(bases[pkg.PackageBase])))
if installed.get(pkg.Name) {
toPrint += bold(green(" (Installed)"))
}
Expand Down Expand Up @@ -669,7 +669,7 @@ func showPkgBuildDiffs(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, cloned stri
}

if !hasDiff {
fmt.Printf("%s %s: %s\n", bold(yellow(arrow)), cyan(formatPkgbase(pkg, bases)), bold("No changes -- skipping"))
fmt.Printf("%s %s: %s\n", bold(yellow(arrow)), cyan(formatPkgbase(bases[pkg.PackageBase])), bold("No changes -- skipping"))
continue
}
}
Expand Down Expand Up @@ -732,7 +732,7 @@ func parseSRCINFOFiles(pkgs []*rpc.Pkg, srcinfos map[string]*gosrc.Srcinfo, base
dir := filepath.Join(config.BuildDir, pkg.PackageBase)

str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n")
fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))
fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(bases[pkg.PackageBase])))

pkgbuild, err := gosrc.ParseFile(filepath.Join(dir, ".SRCINFO"))
if err != nil {
Expand All @@ -750,7 +750,7 @@ func tryParsesrcinfosFile(pkgs []*rpc.Pkg, srcinfos map[string]*gosrc.Srcinfo, b
dir := filepath.Join(config.BuildDir, pkg.PackageBase)

str := bold(cyan("::") + " Parsing SRCINFO (%d/%d): %s\n")
fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))
fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(bases[pkg.PackageBase])))

pkgbuild, err := gosrc.ParseFile(filepath.Join(dir, ".SRCINFO"))
if err != nil {
Expand Down Expand Up @@ -808,7 +808,7 @@ func downloadPkgBuilds(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, toSkip stri
mux.Lock()
downloaded++
str := bold(cyan("::") + " PKGBUILD up to date, Skipping (%d/%d): %s\n")
fmt.Printf(str, downloaded, len(pkgs), cyan(formatPkgbase(pkg, bases)))
fmt.Printf(str, downloaded, len(pkgs), cyan(formatPkgbase(bases[pkg.PackageBase])))
mux.Unlock()
return
}
Expand All @@ -835,7 +835,7 @@ func downloadPkgBuilds(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, toSkip stri
mux.Lock()
downloaded++
str := bold(cyan("::") + " Downloaded PKGBUILD (%d/%d): %s\n")
fmt.Printf(str, downloaded, len(pkgs), cyan(formatPkgbase(pkg, bases)))
fmt.Printf(str, downloaded, len(pkgs), cyan(formatPkgbase(bases[pkg.PackageBase])))
mux.Unlock()
}

Expand All @@ -860,7 +860,7 @@ func downloadPkgBuildsSources(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, inco

err = show(passToMakepkg(dir, args...))
if err != nil {
return fmt.Errorf("Error downloading sources: %s", cyan(formatPkgbase(pkg, bases)))
return fmt.Errorf("Error downloading sources: %s", cyan(formatPkgbase(bases[pkg.PackageBase])))
}
}

Expand Down
2 changes: 1 addition & 1 deletion keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func formatKeysToImport(keys pgpKeySet, bases map[string][]*rpc.Pkg) (string, er
for key, pkgs := range keys {
pkglist := ""
for _, pkg := range pkgs {
pkglist += formatPkgbase(pkg, bases) + " "
pkglist += formatPkgbase(bases[pkg.PackageBase]) + " "
}
pkglist = strings.TrimRight(pkglist, " ")
buffer.WriteString(fmt.Sprintf("\n%s %s, required by: %s", yellow(bold(smallArrow)), cyan(key), cyan(pkglist)))
Expand Down
7 changes: 4 additions & 3 deletions print.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ func (s repoQuery) printSearch() {
// 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)
func formatPkgbase(pkg *rpc.Pkg, bases map[string][]*rpc.Pkg) string {
func formatPkgbase(base []*rpc.Pkg) string {
pkg := base[0]
str := pkg.PackageBase
if len(bases[pkg.PackageBase]) > 1 || pkg.PackageBase != pkg.Name {
if len(base) > 1 || pkg.PackageBase != pkg.Name {
str2 := " ("
for _, split := range bases[pkg.PackageBase] {
for _, split := range base {
str2 += split.Name + " "
}
str2 = str2[:len(str2)-1] + ")"
Expand Down

0 comments on commit 3dc350d

Please sign in to comment.