Skip to content

Commit

Permalink
style(main): remove alpmHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Aug 16, 2020
1 parent 005b293 commit 94f650f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 41 deletions.
9 changes: 5 additions & 4 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/Jguer/go-alpm"

"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/dep"
"github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/settings"
Expand Down Expand Up @@ -65,7 +66,7 @@ func cleanRemove(cmdArgs *settings.Arguments, pkgNames []string) error {
return show(passToPacman(arguments))
}

func syncClean(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func syncClean(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) error {
keepInstalled := false
keepCurrent := false

Expand Down Expand Up @@ -99,7 +100,7 @@ func syncClean(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
fmt.Println(gotext.Get("\nBuild directory:"), config.BuildDir)

if text.ContinueTask(question, true, config.NoConfirm) {
if err := cleanAUR(keepInstalled, keepCurrent, removeAll, alpmHandle); err != nil {
if err := cleanAUR(keepInstalled, keepCurrent, removeAll, dbExecutor); err != nil {
return err
}
}
Expand All @@ -115,13 +116,13 @@ func syncClean(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
return nil
}

func cleanAUR(keepInstalled, keepCurrent, removeAll bool, alpmHandle *alpm.Handle) error {
func cleanAUR(keepInstalled, keepCurrent, removeAll bool, dbExecutor *db.AlpmExecutor) error {
fmt.Println(gotext.Get("removing AUR packages from cache..."))

installedBases := make(stringset.StringSet)
inAURBases := make(stringset.StringSet)

remotePackages, _ := query.GetRemotePackages(config.Runtime.DBExecutor)
remotePackages, _ := query.GetRemotePackages(dbExecutor)

files, err := ioutil.ReadDir(config.BuildDir)
if err != nil {
Expand Down
36 changes: 18 additions & 18 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ getpkgbuild specific options:
-f --force Force download for existing ABS packages`)
}

func handleCmd(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleCmd(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor *db.AlpmExecutor) error {
if cmdArgs.ExistsArg("h", "help") {
return handleHelp(cmdArgs)
}
Expand All @@ -158,29 +158,29 @@ func handleCmd(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
case "F", "files":
return show(passToPacman(cmdArgs))
case "Q", "query":
return handleQuery(cmdArgs, alpmHandle)
return handleQuery(cmdArgs, dbExecutor)
case "R", "remove":
return handleRemove(cmdArgs)
case "S", "sync":
return handleSync(cmdArgs, alpmHandle)
return handleSync(cmdArgs, alpmHandle, dbExecutor)
case "T", "deptest":
return show(passToPacman(cmdArgs))
case "U", "upgrade":
return show(passToPacman(cmdArgs))
case "G", "getpkgbuild":
return handleGetpkgbuild(cmdArgs, alpmHandle)
case "P", "show":
return handlePrint(cmdArgs, alpmHandle, config.Runtime.DBExecutor)
return handlePrint(cmdArgs, alpmHandle, dbExecutor)
case "Y", "--yay":
return handleYay(cmdArgs, alpmHandle)
return handleYay(cmdArgs, alpmHandle, dbExecutor)
}

return fmt.Errorf(gotext.Get("unhandled operation"))
}

func handleQuery(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleQuery(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) error {
if cmdArgs.ExistsArg("u", "upgrades") {
return printUpdateList(cmdArgs, alpmHandle, cmdArgs.ExistsDouble("u", "sysupgrade"))
return printUpdateList(cmdArgs, dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"))
}
return show(passToPacman(cmdArgs))
}
Expand Down Expand Up @@ -227,7 +227,7 @@ func handlePrint(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecuto
case cmdArgs.ExistsArg("g", "currentconfig"):
fmt.Printf("%v", config)
case cmdArgs.ExistsArg("n", "numberupgrades"):
err = printNumberOfUpdates(alpmHandle, cmdArgs.ExistsDouble("u", "sysupgrade"))
err = printNumberOfUpdates(dbExecutor, cmdArgs.ExistsDouble("u", "sysupgrade"))
case cmdArgs.ExistsArg("w", "news"):
double := cmdArgs.ExistsDouble("w", "news")
quiet := cmdArgs.ExistsArg("q", "quiet")
Expand All @@ -244,9 +244,9 @@ func handlePrint(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecuto
return err
}

func handleYay(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleYay(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor *db.AlpmExecutor) error {
if cmdArgs.ExistsArg("gendb") {
return createDevelDB(config.Runtime.VCSPath, alpmHandle)
return createDevelDB(config.Runtime.VCSPath, dbExecutor)
}
if cmdArgs.ExistsDouble("c") {
return cleanDependencies(cmdArgs, alpmHandle, true)
Expand All @@ -255,7 +255,7 @@ func handleYay(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
return cleanDependencies(cmdArgs, alpmHandle, false)
}
if len(cmdArgs.Targets) > 0 {
return handleYogurt(cmdArgs, alpmHandle)
return handleYogurt(cmdArgs, dbExecutor)
}
return nil
}
Expand All @@ -264,12 +264,12 @@ func handleGetpkgbuild(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) err
return getPkgbuilds(cmdArgs.Targets, alpmHandle, cmdArgs.ExistsArg("f", "force"))
}

func handleYogurt(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleYogurt(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor) error {
config.SearchMode = numberMenu
return displayNumberMenu(cmdArgs.Targets, alpmHandle, cmdArgs)
return displayNumberMenu(cmdArgs.Targets, dbExecutor, cmdArgs)
}

func handleSync(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
func handleSync(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, dbExecutor *db.AlpmExecutor) error {
targets := cmdArgs.Targets

if cmdArgs.ExistsArg("s", "search") {
Expand All @@ -284,7 +284,7 @@ func handleSync(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
return show(passToPacman(cmdArgs))
}
if cmdArgs.ExistsArg("c", "clean") {
return syncClean(cmdArgs, alpmHandle)
return syncClean(cmdArgs, dbExecutor)
}
if cmdArgs.ExistsArg("l", "list") {
return syncList(cmdArgs, alpmHandle)
Expand Down Expand Up @@ -317,7 +317,7 @@ func handleRemove(cmdArgs *settings.Arguments) error {
}

// NumberMenu presents a CLI for selecting packages to install.
func displayNumberMenu(pkgS []string, alpmHandle *alpm.Handle, cmdArgs *settings.Arguments) error {
func displayNumberMenu(pkgS []string, dbExecutor *db.AlpmExecutor, cmdArgs *settings.Arguments) error {
var (
aurErr, repoErr error
aq aurQuery
Expand All @@ -332,7 +332,7 @@ func displayNumberMenu(pkgS []string, alpmHandle *alpm.Handle, cmdArgs *settings
lenaq = len(aq)
}
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
pq = queryRepo(pkgS, config.Runtime.DBExecutor)
pq = queryRepo(pkgS, dbExecutor)
lenpq = len(pq)
if repoErr != nil {
return repoErr
Expand Down Expand Up @@ -427,7 +427,7 @@ func displayNumberMenu(pkgS []string, alpmHandle *alpm.Handle, cmdArgs *settings
sudoLoopBackground()
}

return install(arguments, config.Runtime.DBExecutor, true)
return install(arguments, dbExecutor, true)
}

func syncList(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle) error {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ func main() {
exitOnError(err)
config.Runtime.DBExecutor, err = db.NewAlpmExecutor(config.Runtime.AlpmHandle, runtime.PacmanConf, questionCallback)
exitOnError(err)
exitOnError(handleCmd(cmdArgs, config.Runtime.AlpmHandle))
exitOnError(handleCmd(cmdArgs, config.Runtime.AlpmHandle, config.Runtime.DBExecutor))
os.Exit(cleanup(config.Runtime.AlpmHandle))
}
13 changes: 5 additions & 8 deletions pkg/query/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ outer:

// GetRemotePackages returns packages with no correspondence in SyncDBS.
func GetRemotePackages(dbExecutor *db.AlpmExecutor) (
[]db.RepoPackage,
[]string) {
remoteNames := []string{}
remote := []db.RepoPackage{}

remote []db.RepoPackage,
remoteNames []string) {
outer:
for _, localpkg := range dbExecutor.LocalPackages() {
for _, syncpkg := range dbExecutor.SyncPackages() {
Expand All @@ -47,14 +44,14 @@ func RemoveInvalidTargets(targets []string, mode settings.TargetMode) []string {
filteredTargets := make([]string, 0)

for _, target := range targets {
db, _ := text.SplitDBFromName(target)
dbName, _ := text.SplitDBFromName(target)

if db == "aur" && mode == settings.ModeRepo {
if dbName == "aur" && mode == settings.ModeRepo {
text.Warnln(gotext.Get("%s: can't use target with option --repo -- skipping", text.Cyan(target)))
continue
}

if db != "aur" && db != "" && mode == settings.ModeAUR {
if dbName != "aur" && dbName != "" && mode == settings.ModeAUR {
text.Warnln(gotext.Get("%s: can't use target with option --aur -- skipping", text.Cyan(target)))
continue
}
Expand Down
10 changes: 5 additions & 5 deletions print.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ func localStatistics(alpmHandle *alpm.Handle) error {
}

// TODO: Make it less hacky
func printNumberOfUpdates(alpmHandle *alpm.Handle, enableDowngrade bool) error {
func printNumberOfUpdates(dbExecutor *db.AlpmExecutor, enableDowngrade bool) error {
warnings := query.NewWarnings()
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil
aurUp, repoUp, err := upList(warnings, config.Runtime.DBExecutor, enableDowngrade)
aurUp, repoUp, err := upList(warnings, dbExecutor, enableDowngrade)
os.Stdout = old // restoring the real stdout
if err != nil {
return err
Expand All @@ -207,17 +207,17 @@ func printNumberOfUpdates(alpmHandle *alpm.Handle, enableDowngrade bool) error {
}

// TODO: Make it less hacky
func printUpdateList(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, enableDowngrade bool) error {
func printUpdateList(cmdArgs *settings.Arguments, dbExecutor *db.AlpmExecutor, enableDowngrade bool) error {
targets := stringset.FromSlice(cmdArgs.Targets)
warnings := query.NewWarnings()
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil
localNames, remoteNames, err := query.GetPackageNamesBySource(config.Runtime.DBExecutor)
localNames, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
if err != nil {
return err
}

aurUp, repoUp, err := upList(warnings, config.Runtime.DBExecutor, enableDowngrade)
aurUp, repoUp, err := upList(warnings, dbExecutor, enableDowngrade)
os.Stdout = old // restoring the real stdout
if err != nil {
return err
Expand Down
7 changes: 6 additions & 1 deletion upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ func upAUR(remote []db.RepoPackage, aurdata map[string]*rpc.Pkg) upgrade.UpSlice
if pkg.ShouldIgnore() {
printIgnoringPackage(pkg, aurPkg.Version)
} else {
toUpgrade = append(toUpgrade, upgrade.Upgrade{Name: aurPkg.Name, Repository: "aur", LocalVersion: pkg.Version(), RemoteVersion: aurPkg.Version})
toUpgrade = append(toUpgrade,
upgrade.Upgrade{
Name: aurPkg.Name,
Repository: "aur",
LocalVersion: pkg.Version(),
RemoteVersion: aurPkg.Version})
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
gosrc "github.com/Morganamilo/go-srcinfo"
"github.com/leonelquinteros/gotext"

"github.com/Jguer/go-alpm"

"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/dep"
"github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/stringset"
Expand All @@ -32,11 +31,11 @@ type (
)

// createDevelDB forces yay to create a DB of the existing development packages
func createDevelDB(vcsFilePath string, alpmHandle *alpm.Handle) error {
func createDevelDB(vcsFilePath string, dbExecutor *db.AlpmExecutor) error {
var mux sync.Mutex
var wg sync.WaitGroup

_, remoteNames, err := query.GetPackageNamesBySource(config.Runtime.DBExecutor)
_, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
if err != nil {
return err
}
Expand Down

0 comments on commit 94f650f

Please sign in to comment.