mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 09:07:21 +01:00
refactor(parser): unify atleast modes
This commit is contained in:
parent
5c11c01d85
commit
f42cbde6db
4
clean.go
4
clean.go
@ -56,14 +56,14 @@ func syncClean(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||
}
|
||||
}
|
||||
|
||||
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastRepo() {
|
||||
if err := config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(
|
||||
cmdArgs, config.Runtime.Mode, settings.NoConfirm)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !(config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny) {
|
||||
if !config.Runtime.Mode.AtLeastAUR() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
18
cmd.go
18
cmd.go
@ -354,11 +354,11 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *parser.Ar
|
||||
|
||||
pkgS = query.RemoveInvalidTargets(pkgS, config.Runtime.Mode)
|
||||
|
||||
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastAUR() {
|
||||
aq, aurErr = narrowSearch(config.Runtime.AURClient, pkgS, true)
|
||||
lenaq = len(aq)
|
||||
}
|
||||
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastRepo() {
|
||||
pq = queryRepo(pkgS, dbExecutor)
|
||||
lenpq = len(pq)
|
||||
if repoErr != nil {
|
||||
@ -372,17 +372,17 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *parser.Ar
|
||||
|
||||
switch config.SortMode {
|
||||
case settings.TopDown:
|
||||
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastRepo() {
|
||||
pq.printSearch(dbExecutor)
|
||||
}
|
||||
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastAUR() {
|
||||
aq.printSearch(lenpq+1, dbExecutor)
|
||||
}
|
||||
case settings.BottomUp:
|
||||
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastAUR() {
|
||||
aq.printSearch(lenpq+1, dbExecutor)
|
||||
}
|
||||
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastRepo() {
|
||||
pq.printSearch(dbExecutor)
|
||||
}
|
||||
default:
|
||||
@ -457,13 +457,13 @@ func syncList(httpClient *http.Client, cmdArgs *parser.Arguments, dbExecutor db.
|
||||
aur := false
|
||||
|
||||
for i := len(cmdArgs.Targets) - 1; i >= 0; i-- {
|
||||
if cmdArgs.Targets[i] == "aur" && (config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeAUR) {
|
||||
if cmdArgs.Targets[i] == "aur" && config.Runtime.Mode.AtLeastAUR() {
|
||||
cmdArgs.Targets = append(cmdArgs.Targets[:i], cmdArgs.Targets[i+1:]...)
|
||||
aur = true
|
||||
}
|
||||
}
|
||||
|
||||
if (config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeAUR) && (len(cmdArgs.Targets) == 0 || aur) {
|
||||
if config.Runtime.Mode.AtLeastAUR() && (len(cmdArgs.Targets) == 0 || aur) {
|
||||
req, err := http.NewRequestWithContext(context.Background(), "GET", config.AURURL+"/packages.gz", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -494,7 +494,7 @@ func syncList(httpClient *http.Client, cmdArgs *parser.Arguments, dbExecutor db.
|
||||
}
|
||||
}
|
||||
|
||||
if (config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeRepo) && (len(cmdArgs.Targets) != 0 || !aur) {
|
||||
if config.Runtime.Mode.AtLeastRepo() && (len(cmdArgs.Targets) != 0 || !aur) {
|
||||
return config.Runtime.CmdBuilder.Show(config.Runtime.CmdBuilder.BuildPacmanCmd(
|
||||
cmdArgs, config.Runtime.Mode, settings.NoConfirm))
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func install(cmdArgs *parser.Arguments, dbExecutor db.Executor, ignoreProviders
|
||||
config.Runtime.CmdBuilder.AddMakepkgFlag("-d")
|
||||
}
|
||||
|
||||
if config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeRepo {
|
||||
if config.Runtime.Mode.AtLeastRepo() {
|
||||
if config.CombinedUpgrade {
|
||||
if refreshArg {
|
||||
err = earlyRefresh(cmdArgs)
|
||||
@ -196,7 +196,8 @@ func install(cmdArgs *parser.Arguments, dbExecutor db.Executor, ignoreProviders
|
||||
arguments.AddTarget(pkg)
|
||||
}
|
||||
|
||||
if len(do.Aur) == 0 && len(arguments.Targets) == 0 && (!cmdArgs.ExistsArg("u", "sysupgrade") || config.Runtime.Mode == parser.ModeAUR) {
|
||||
if len(do.Aur) == 0 && len(arguments.Targets) == 0 &&
|
||||
(!cmdArgs.ExistsArg("u", "sysupgrade") || config.Runtime.Mode == parser.ModeAUR) {
|
||||
fmt.Println(gotext.Get(" there is nothing to do"))
|
||||
return nil
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ func (dp *Pool) ResolveTargets(pkgs []string,
|
||||
dp.Targets = append(dp.Targets, target)
|
||||
}
|
||||
|
||||
if len(aurTargets) > 0 && (mode == parser.ModeAny || mode == parser.ModeAUR) {
|
||||
if len(aurTargets) > 0 && mode.AtLeastAUR() {
|
||||
return dp.resolveAURPackages(aurTargets, true, ignoreProviders, noConfirm, provides, rebuild, splitN, noDeps, noCheckDeps)
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ func getPackageUsableName(dbExecutor DBSearcher, target string, mode parser.Targ
|
||||
aur = true
|
||||
|
||||
dbName, name := text.SplitDBFromName(target)
|
||||
if dbName != "aur" && (mode == parser.ModeAny || mode == parser.ModeRepo) {
|
||||
if dbName != "aur" && mode.AtLeastRepo() {
|
||||
var pkg alpm.IPackage
|
||||
if dbName != "" {
|
||||
pkg = dbExecutor.SatisfierFromDB(name, dbName)
|
||||
|
@ -41,12 +41,12 @@ func RemoveInvalidTargets(targets []string, mode parser.TargetMode) []string {
|
||||
for _, target := range targets {
|
||||
dbName, _ := text.SplitDBFromName(target)
|
||||
|
||||
if dbName == "aur" && mode == parser.ModeRepo {
|
||||
if dbName == "aur" && !mode.AtLeastAUR() {
|
||||
text.Warnln(gotext.Get("%s: can't use target with option --repo -- skipping", text.Cyan(target)))
|
||||
continue
|
||||
}
|
||||
|
||||
if dbName != "aur" && dbName != "" && mode == parser.ModeAUR {
|
||||
if dbName != "aur" && dbName != "" && !mode.AtLeastRepo() {
|
||||
text.Warnln(gotext.Get("%s: can't use target with option --aur -- skipping", text.Cyan(target)))
|
||||
continue
|
||||
}
|
||||
|
@ -7,3 +7,11 @@ const (
|
||||
ModeAUR
|
||||
ModeRepo
|
||||
)
|
||||
|
||||
func (mode TargetMode) AtLeastAUR() bool {
|
||||
return mode == ModeAny || mode == ModeAUR
|
||||
}
|
||||
|
||||
func (mode TargetMode) AtLeastRepo() bool {
|
||||
return mode == ModeAny || mode == ModeRepo
|
||||
}
|
||||
|
12
query.go
12
query.go
@ -155,26 +155,26 @@ func syncSearch(pkgS []string, aurClient *aur.Client, dbExecutor db.Executor) (e
|
||||
var aq aurQuery
|
||||
var pq repoQuery
|
||||
|
||||
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastAUR() {
|
||||
aq, aurErr = narrowSearch(aurClient, pkgS, true)
|
||||
}
|
||||
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastRepo() {
|
||||
pq = queryRepo(pkgS, dbExecutor)
|
||||
}
|
||||
|
||||
switch config.SortMode {
|
||||
case settings.TopDown:
|
||||
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastRepo() {
|
||||
pq.printSearch(dbExecutor)
|
||||
}
|
||||
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastAUR() {
|
||||
aq.printSearch(1, dbExecutor)
|
||||
}
|
||||
case settings.BottomUp:
|
||||
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastAUR() {
|
||||
aq.printSearch(1, dbExecutor)
|
||||
}
|
||||
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||
if config.Runtime.Mode.AtLeastRepo() {
|
||||
pq.printSearch(dbExecutor)
|
||||
}
|
||||
default:
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/Jguer/yay/v10/pkg/intrange"
|
||||
"github.com/Jguer/yay/v10/pkg/multierror"
|
||||
"github.com/Jguer/yay/v10/pkg/query"
|
||||
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||
"github.com/Jguer/yay/v10/pkg/text"
|
||||
"github.com/Jguer/yay/v10/pkg/upgrade"
|
||||
@ -48,7 +47,7 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
||||
}
|
||||
}
|
||||
|
||||
if config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeRepo {
|
||||
if config.Runtime.Mode.AtLeastRepo() {
|
||||
text.OperationInfoln(gotext.Get("Searching databases for updates..."))
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
@ -58,7 +57,7 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
||||
}()
|
||||
}
|
||||
|
||||
if config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeAUR {
|
||||
if config.Runtime.Mode.AtLeastAUR() {
|
||||
text.OperationInfoln(gotext.Get("Searching AUR for updates..."))
|
||||
|
||||
var _aurdata []*aur.Pkg
|
||||
|
Loading…
Reference in New Issue
Block a user