mirror of
https://github.com/Jguer/yay.git
synced 2025-11-30 00:04:05 -05:00
refactor(settings): move args to own package to allow pacman cmd builder
This commit is contained in:
parent
456d83ef51
commit
1a2e5b9529
11
clean.go
11
clean.go
@ -12,12 +12,13 @@ import (
|
|||||||
"github.com/Jguer/yay/v10/pkg/dep"
|
"github.com/Jguer/yay/v10/pkg/dep"
|
||||||
"github.com/Jguer/yay/v10/pkg/query"
|
"github.com/Jguer/yay/v10/pkg/query"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CleanDependencies removes all dangling dependencies in system
|
// CleanDependencies removes all dangling dependencies in system
|
||||||
func cleanDependencies(cmdArgs *settings.Arguments, dbExecutor db.Executor, removeOptional bool) error {
|
func cleanDependencies(cmdArgs *parser.Arguments, dbExecutor db.Executor, removeOptional bool) error {
|
||||||
hanging := hangingPackages(removeOptional, dbExecutor)
|
hanging := hangingPackages(removeOptional, dbExecutor)
|
||||||
if len(hanging) != 0 {
|
if len(hanging) != 0 {
|
||||||
return cleanRemove(cmdArgs, hanging)
|
return cleanRemove(cmdArgs, hanging)
|
||||||
@ -27,7 +28,7 @@ func cleanDependencies(cmdArgs *settings.Arguments, dbExecutor db.Executor, remo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CleanRemove sends a full removal command to pacman with the pkgName slice
|
// CleanRemove sends a full removal command to pacman with the pkgName slice
|
||||||
func cleanRemove(cmdArgs *settings.Arguments, pkgNames []string) error {
|
func cleanRemove(cmdArgs *parser.Arguments, pkgNames []string) error {
|
||||||
if len(pkgNames) == 0 {
|
if len(pkgNames) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -39,7 +40,7 @@ func cleanRemove(cmdArgs *settings.Arguments, pkgNames []string) error {
|
|||||||
return config.Runtime.CmdRunner.Show(passToPacman(arguments))
|
return config.Runtime.CmdRunner.Show(passToPacman(arguments))
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncClean(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func syncClean(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
keepInstalled := false
|
keepInstalled := false
|
||||||
keepCurrent := false
|
keepCurrent := false
|
||||||
|
|
||||||
@ -53,13 +54,13 @@ func syncClean(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||||
if err := config.Runtime.CmdRunner.Show(passToPacman(cmdArgs)); err != nil {
|
if err := config.Runtime.CmdRunner.Show(passToPacman(cmdArgs)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny) {
|
if !(config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
45
cmd.go
45
cmd.go
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/Jguer/yay/v10/pkg/news"
|
"github.com/Jguer/yay/v10/pkg/news"
|
||||||
"github.com/Jguer/yay/v10/pkg/query"
|
"github.com/Jguer/yay/v10/pkg/query"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
"github.com/Jguer/yay/v10/pkg/upgrade"
|
"github.com/Jguer/yay/v10/pkg/upgrade"
|
||||||
"github.com/Jguer/yay/v10/pkg/vcs"
|
"github.com/Jguer/yay/v10/pkg/vcs"
|
||||||
@ -143,12 +144,12 @@ getpkgbuild specific options:
|
|||||||
-p --print Print pkgbuild of packages`)
|
-p --print Print pkgbuild of packages`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleCmd(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func handleCmd(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
if cmdArgs.ExistsArg("h", "help") {
|
if cmdArgs.ExistsArg("h", "help") {
|
||||||
return handleHelp(cmdArgs)
|
return handleHelp(cmdArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.SudoLoop && cmdArgs.NeedRoot(config.Runtime) {
|
if config.SudoLoop && cmdArgs.NeedRoot(config.Runtime.Mode) {
|
||||||
sudoLoopBackground()
|
sudoLoopBackground()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +185,7 @@ func handleCmd(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
|||||||
// getFilter returns filter function which can keep packages which were only
|
// getFilter returns filter function which can keep packages which were only
|
||||||
// explicitly installed or ones installed as dependencies for showing available
|
// explicitly installed or ones installed as dependencies for showing available
|
||||||
// updates or their count.
|
// updates or their count.
|
||||||
func getFilter(cmdArgs *settings.Arguments) (upgrade.Filter, error) {
|
func getFilter(cmdArgs *parser.Arguments) (upgrade.Filter, error) {
|
||||||
deps, explicit := cmdArgs.ExistsArg("d", "deps"), cmdArgs.ExistsArg("e", "explicit")
|
deps, explicit := cmdArgs.ExistsArg("d", "deps"), cmdArgs.ExistsArg("e", "explicit")
|
||||||
switch {
|
switch {
|
||||||
case deps && explicit:
|
case deps && explicit:
|
||||||
@ -203,7 +204,7 @@ func getFilter(cmdArgs *settings.Arguments) (upgrade.Filter, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleQuery(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func handleQuery(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
if cmdArgs.ExistsArg("u", "upgrades") {
|
if cmdArgs.ExistsArg("u", "upgrades") {
|
||||||
filter, err := getFilter(cmdArgs)
|
filter, err := getFilter(cmdArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -214,7 +215,7 @@ func handleQuery(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
|||||||
return config.Runtime.CmdRunner.Show(passToPacman(cmdArgs))
|
return config.Runtime.CmdRunner.Show(passToPacman(cmdArgs))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleHelp(cmdArgs *settings.Arguments) error {
|
func handleHelp(cmdArgs *parser.Arguments) error {
|
||||||
if cmdArgs.Op == "Y" || cmdArgs.Op == "yay" {
|
if cmdArgs.Op == "Y" || cmdArgs.Op == "yay" {
|
||||||
usage()
|
usage()
|
||||||
return nil
|
return nil
|
||||||
@ -226,7 +227,7 @@ func handleVersion() {
|
|||||||
fmt.Printf("yay v%s - libalpm v%s\n", yayVersion, alpm.Version())
|
fmt.Printf("yay v%s - libalpm v%s\n", yayVersion, alpm.Version())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePrint(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func handlePrint(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
switch {
|
switch {
|
||||||
case cmdArgs.ExistsArg("d", "defaultconfig"):
|
case cmdArgs.ExistsArg("d", "defaultconfig"):
|
||||||
tmpConfig := settings.DefaultConfig()
|
tmpConfig := settings.DefaultConfig()
|
||||||
@ -257,7 +258,7 @@ func handlePrint(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleYay(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func handleYay(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
if cmdArgs.ExistsArg("gendb") {
|
if cmdArgs.ExistsArg("gendb") {
|
||||||
return createDevelDB(config, dbExecutor)
|
return createDevelDB(config, dbExecutor)
|
||||||
}
|
}
|
||||||
@ -273,19 +274,19 @@ func handleYay(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleGetpkgbuild(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func handleGetpkgbuild(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
if cmdArgs.ExistsArg("p", "print") {
|
if cmdArgs.ExistsArg("p", "print") {
|
||||||
return printPkgbuilds(dbExecutor, config.Runtime.HTTPClient, cmdArgs.Targets)
|
return printPkgbuilds(dbExecutor, config.Runtime.HTTPClient, cmdArgs.Targets)
|
||||||
}
|
}
|
||||||
return getPkgbuilds(dbExecutor, config, cmdArgs.Targets, cmdArgs.ExistsArg("f", "force"))
|
return getPkgbuilds(dbExecutor, config, cmdArgs.Targets, cmdArgs.ExistsArg("f", "force"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleYogurt(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func handleYogurt(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
config.SearchMode = numberMenu
|
config.SearchMode = numberMenu
|
||||||
return displayNumberMenu(cmdArgs.Targets, dbExecutor, cmdArgs)
|
return displayNumberMenu(cmdArgs.Targets, dbExecutor, cmdArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSync(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func handleSync(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
targets := cmdArgs.Targets
|
targets := cmdArgs.Targets
|
||||||
|
|
||||||
if cmdArgs.ExistsArg("s", "search") {
|
if cmdArgs.ExistsArg("s", "search") {
|
||||||
@ -323,7 +324,7 @@ func handleSync(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRemove(cmdArgs *settings.Arguments, localCache *vcs.InfoStore) error {
|
func handleRemove(cmdArgs *parser.Arguments, localCache *vcs.InfoStore) error {
|
||||||
err := config.Runtime.CmdRunner.Show(passToPacman(cmdArgs))
|
err := config.Runtime.CmdRunner.Show(passToPacman(cmdArgs))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
localCache.RemovePackage(cmdArgs.Targets)
|
localCache.RemovePackage(cmdArgs.Targets)
|
||||||
@ -333,7 +334,7 @@ func handleRemove(cmdArgs *settings.Arguments, localCache *vcs.InfoStore) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NumberMenu presents a CLI for selecting packages to install.
|
// NumberMenu presents a CLI for selecting packages to install.
|
||||||
func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *settings.Arguments) error {
|
func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *parser.Arguments) error {
|
||||||
var (
|
var (
|
||||||
aurErr, repoErr error
|
aurErr, repoErr error
|
||||||
aq aurQuery
|
aq aurQuery
|
||||||
@ -343,11 +344,11 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *settings.
|
|||||||
|
|
||||||
pkgS = query.RemoveInvalidTargets(pkgS, config.Runtime.Mode)
|
pkgS = query.RemoveInvalidTargets(pkgS, config.Runtime.Mode)
|
||||||
|
|
||||||
if config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||||
aq, aurErr = narrowSearch(config.Runtime.AURClient, pkgS, true)
|
aq, aurErr = narrowSearch(config.Runtime.AURClient, pkgS, true)
|
||||||
lenaq = len(aq)
|
lenaq = len(aq)
|
||||||
}
|
}
|
||||||
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||||
pq = queryRepo(pkgS, dbExecutor)
|
pq = queryRepo(pkgS, dbExecutor)
|
||||||
lenpq = len(pq)
|
lenpq = len(pq)
|
||||||
if repoErr != nil {
|
if repoErr != nil {
|
||||||
@ -361,17 +362,17 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *settings.
|
|||||||
|
|
||||||
switch config.SortMode {
|
switch config.SortMode {
|
||||||
case settings.TopDown:
|
case settings.TopDown:
|
||||||
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||||
pq.printSearch(dbExecutor)
|
pq.printSearch(dbExecutor)
|
||||||
}
|
}
|
||||||
if config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||||
aq.printSearch(lenpq+1, dbExecutor)
|
aq.printSearch(lenpq+1, dbExecutor)
|
||||||
}
|
}
|
||||||
case settings.BottomUp:
|
case settings.BottomUp:
|
||||||
if config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||||
aq.printSearch(lenpq+1, dbExecutor)
|
aq.printSearch(lenpq+1, dbExecutor)
|
||||||
}
|
}
|
||||||
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||||
pq.printSearch(dbExecutor)
|
pq.printSearch(dbExecutor)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -446,17 +447,17 @@ func displayNumberMenu(pkgS []string, dbExecutor db.Executor, cmdArgs *settings.
|
|||||||
return install(arguments, dbExecutor, true)
|
return install(arguments, dbExecutor, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncList(httpClient *http.Client, cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func syncList(httpClient *http.Client, cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
aur := false
|
aur := false
|
||||||
|
|
||||||
for i := len(cmdArgs.Targets) - 1; i >= 0; i-- {
|
for i := len(cmdArgs.Targets) - 1; i >= 0; i-- {
|
||||||
if cmdArgs.Targets[i] == "aur" && (config.Runtime.Mode == settings.ModeAny || config.Runtime.Mode == settings.ModeAUR) {
|
if cmdArgs.Targets[i] == "aur" && (config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeAUR) {
|
||||||
cmdArgs.Targets = append(cmdArgs.Targets[:i], cmdArgs.Targets[i+1:]...)
|
cmdArgs.Targets = append(cmdArgs.Targets[:i], cmdArgs.Targets[i+1:]...)
|
||||||
aur = true
|
aur = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.Runtime.Mode == settings.ModeAny || config.Runtime.Mode == settings.ModeAUR) && (len(cmdArgs.Targets) == 0 || aur) {
|
if (config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeAUR) && (len(cmdArgs.Targets) == 0 || aur) {
|
||||||
req, err := http.NewRequestWithContext(context.Background(), "GET", config.AURURL+"/packages.gz", nil)
|
req, err := http.NewRequestWithContext(context.Background(), "GET", config.AURURL+"/packages.gz", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -487,7 +488,7 @@ func syncList(httpClient *http.Client, cmdArgs *settings.Arguments, dbExecutor d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.Runtime.Mode == settings.ModeAny || config.Runtime.Mode == settings.ModeRepo) && (len(cmdArgs.Targets) != 0 || !aur) {
|
if (config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeRepo) && (len(cmdArgs.Targets) != 0 || !aur) {
|
||||||
return config.Runtime.CmdRunner.Show(passToPacman(cmdArgs))
|
return config.Runtime.CmdRunner.Show(passToPacman(cmdArgs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
exec.go
7
exec.go
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
|
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -56,10 +57,10 @@ func waitLock(dbPath string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func passToPacman(args *settings.Arguments) *exec.Cmd {
|
func passToPacman(args *parser.Arguments) *exec.Cmd {
|
||||||
argArr := make([]string, 0, 32)
|
argArr := make([]string, 0, 32)
|
||||||
|
|
||||||
if args.NeedRoot(config.Runtime) {
|
if args.NeedRoot(config.Runtime.Mode) {
|
||||||
argArr = append(argArr, config.SudoBin)
|
argArr = append(argArr, config.SudoBin)
|
||||||
argArr = append(argArr, strings.Fields(config.SudoFlags)...)
|
argArr = append(argArr, strings.Fields(config.SudoFlags)...)
|
||||||
}
|
}
|
||||||
@ -74,7 +75,7 @@ func passToPacman(args *settings.Arguments) *exec.Cmd {
|
|||||||
argArr = append(argArr, "--config", config.PacmanConf, "--")
|
argArr = append(argArr, "--config", config.PacmanConf, "--")
|
||||||
argArr = append(argArr, args.Targets...)
|
argArr = append(argArr, args.Targets...)
|
||||||
|
|
||||||
if args.NeedRoot(config.Runtime) {
|
if args.NeedRoot(config.Runtime.Mode) {
|
||||||
waitLock(config.Runtime.PacmanConf.DBPath)
|
waitLock(config.Runtime.PacmanConf.DBPath)
|
||||||
}
|
}
|
||||||
return exec.Command(argArr[0], argArr[1:]...)
|
return exec.Command(argArr[0], argArr[1:]...)
|
||||||
|
|||||||
44
install.go
44
install.go
@ -23,13 +23,14 @@ import (
|
|||||||
"github.com/Jguer/yay/v10/pkg/pgp"
|
"github.com/Jguer/yay/v10/pkg/pgp"
|
||||||
"github.com/Jguer/yay/v10/pkg/query"
|
"github.com/Jguer/yay/v10/pkg/query"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
const gitEmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
const gitEmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
||||||
|
|
||||||
func asdeps(cmdArgs *settings.Arguments, pkgs []string) (err error) {
|
func asdeps(cmdArgs *parser.Arguments, pkgs []string) (err error) {
|
||||||
if len(pkgs) == 0 {
|
if len(pkgs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -45,7 +46,7 @@ func asdeps(cmdArgs *settings.Arguments, pkgs []string) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func asexp(cmdArgs *settings.Arguments, pkgs []string) (err error) {
|
func asexp(cmdArgs *parser.Arguments, pkgs []string) (err error) {
|
||||||
if len(pkgs) == 0 {
|
if len(pkgs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -62,23 +63,24 @@ func asexp(cmdArgs *settings.Arguments, pkgs []string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Install handles package installs
|
// Install handles package installs
|
||||||
func install(cmdArgs *settings.Arguments, dbExecutor db.Executor, ignoreProviders bool) (err error) {
|
func install(cmdArgs *parser.Arguments, dbExecutor db.Executor, ignoreProviders bool) (err error) {
|
||||||
var incompatible stringset.StringSet
|
var (
|
||||||
var do *dep.Order
|
incompatible stringset.StringSet
|
||||||
|
do *dep.Order
|
||||||
var srcinfos map[string]*gosrc.Srcinfo
|
srcinfos map[string]*gosrc.Srcinfo
|
||||||
noDeps := cmdArgs.ExistsDouble("d", "nodeps")
|
noDeps = cmdArgs.ExistsDouble("d", "nodeps")
|
||||||
noCheck := strings.Contains(config.MFlags, "--nocheck")
|
noCheck = strings.Contains(config.MFlags, "--nocheck")
|
||||||
assumeInstalled := cmdArgs.GetArgs("assume-installed")
|
assumeInstalled = cmdArgs.GetArgs("assume-installed")
|
||||||
sysupgradeArg := cmdArgs.ExistsArg("u", "sysupgrade")
|
sysupgradeArg = cmdArgs.ExistsArg("u", "sysupgrade")
|
||||||
refreshArg := cmdArgs.ExistsArg("y", "refresh")
|
refreshArg = cmdArgs.ExistsArg("y", "refresh")
|
||||||
warnings := query.NewWarnings()
|
warnings = query.NewWarnings()
|
||||||
|
)
|
||||||
|
|
||||||
if noDeps {
|
if noDeps {
|
||||||
config.Runtime.CmdBuilder.MakepkgFlags = append(config.Runtime.CmdBuilder.MakepkgFlags, "-d")
|
config.Runtime.CmdBuilder.MakepkgFlags = append(config.Runtime.CmdBuilder.MakepkgFlags, "-d")
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Runtime.Mode == settings.ModeAny || config.Runtime.Mode == settings.ModeRepo {
|
if config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeRepo {
|
||||||
if config.CombinedUpgrade {
|
if config.CombinedUpgrade {
|
||||||
if refreshArg {
|
if refreshArg {
|
||||||
err = earlyRefresh(cmdArgs)
|
err = earlyRefresh(cmdArgs)
|
||||||
@ -118,7 +120,7 @@ func install(cmdArgs *settings.Arguments, dbExecutor db.Executor, ignoreProvider
|
|||||||
arguments.Op = "S"
|
arguments.Op = "S"
|
||||||
arguments.ClearTargets()
|
arguments.ClearTargets()
|
||||||
|
|
||||||
if config.Runtime.Mode == settings.ModeAUR {
|
if config.Runtime.Mode == parser.ModeAUR {
|
||||||
arguments.DelArg("u", "sysupgrade")
|
arguments.DelArg("u", "sysupgrade")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +193,7 @@ func install(cmdArgs *settings.Arguments, dbExecutor db.Executor, ignoreProvider
|
|||||||
arguments.AddTarget(pkg)
|
arguments.AddTarget(pkg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(do.Aur) == 0 && len(arguments.Targets) == 0 && (!cmdArgs.ExistsArg("u", "sysupgrade") || config.Runtime.Mode == settings.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"))
|
fmt.Println(gotext.Get(" there is nothing to do"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -386,7 +388,7 @@ func install(cmdArgs *settings.Arguments, dbExecutor db.Executor, ignoreProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
func removeMake(do *dep.Order) error {
|
func removeMake(do *dep.Order) error {
|
||||||
removeArguments := settings.MakeArguments()
|
removeArguments := parser.MakeArguments()
|
||||||
err := removeArguments.AddArg("R", "u")
|
err := removeArguments.AddArg("R", "u")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -421,14 +423,14 @@ func inRepos(dbExecutor db.Executor, pkg string) bool {
|
|||||||
return exists || len(dbExecutor.PackagesFromGroup(target.Name)) > 0
|
return exists || len(dbExecutor.PackagesFromGroup(target.Name)) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func earlyPacmanCall(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
|
func earlyPacmanCall(cmdArgs *parser.Arguments, dbExecutor db.Executor) error {
|
||||||
arguments := cmdArgs.Copy()
|
arguments := cmdArgs.Copy()
|
||||||
arguments.Op = "S"
|
arguments.Op = "S"
|
||||||
targets := cmdArgs.Targets
|
targets := cmdArgs.Targets
|
||||||
cmdArgs.ClearTargets()
|
cmdArgs.ClearTargets()
|
||||||
arguments.ClearTargets()
|
arguments.ClearTargets()
|
||||||
|
|
||||||
if config.Runtime.Mode == settings.ModeRepo {
|
if config.Runtime.Mode == parser.ModeRepo {
|
||||||
arguments.Targets = targets
|
arguments.Targets = targets
|
||||||
} else {
|
} else {
|
||||||
// separate aur and repo targets
|
// separate aur and repo targets
|
||||||
@ -450,7 +452,7 @@ func earlyPacmanCall(cmdArgs *settings.Arguments, dbExecutor db.Executor) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func earlyRefresh(cmdArgs *settings.Arguments) error {
|
func earlyRefresh(cmdArgs *parser.Arguments) error {
|
||||||
arguments := cmdArgs.Copy()
|
arguments := cmdArgs.Copy()
|
||||||
cmdArgs.DelArg("y", "refresh")
|
cmdArgs.DelArg("y", "refresh")
|
||||||
arguments.DelArg("u", "sysupgrade")
|
arguments.DelArg("u", "sysupgrade")
|
||||||
@ -855,7 +857,7 @@ func downloadPkgbuildsSources(bases []dep.Base, incompatible stringset.StringSet
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buildInstallPkgbuilds(
|
func buildInstallPkgbuilds(
|
||||||
cmdArgs *settings.Arguments,
|
cmdArgs *parser.Arguments,
|
||||||
dbExecutor db.Executor,
|
dbExecutor db.Executor,
|
||||||
dp *dep.Pool,
|
dp *dep.Pool,
|
||||||
do *dep.Order,
|
do *dep.Order,
|
||||||
|
|||||||
7
main.go
7
main.go
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/Jguer/yay/v10/pkg/db"
|
"github.com/Jguer/yay/v10/pkg/db"
|
||||||
"github.com/Jguer/yay/v10/pkg/db/ialpm"
|
"github.com/Jguer/yay/v10/pkg/db/ialpm"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ func initGotext() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initAlpm(cmdArgs *settings.Arguments, pacmanConfigPath string) (*pacmanconf.Config, bool, error) {
|
func initAlpm(cmdArgs *parser.Arguments, pacmanConfigPath string) (*pacmanconf.Config, bool, error) {
|
||||||
root := "/"
|
root := "/"
|
||||||
if value, _, exists := cmdArgs.GetArg("root", "r"); exists {
|
if value, _, exists := cmdArgs.GetArg("root", "r"); exists {
|
||||||
root = value
|
root = value
|
||||||
@ -98,8 +99,8 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdArgs := settings.MakeArguments()
|
cmdArgs := parser.MakeArguments()
|
||||||
err = cmdArgs.ParseCommandLine(config)
|
err = config.ParseCommandLine(cmdArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if str := err.Error(); str != "" {
|
if str := err.Error(); str != "" {
|
||||||
fmt.Fprintln(os.Stderr, str)
|
fmt.Fprintln(os.Stderr, str)
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/Morganamilo/go-pacmanconf"
|
"github.com/Morganamilo/go-pacmanconf"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPacmanConf(t *testing.T) {
|
func TestPacmanConf(t *testing.T) {
|
||||||
@ -41,7 +41,7 @@ func TestPacmanConf(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pacmanConf, color, err := initAlpm(settings.MakeArguments(), "testdata/pacman.conf")
|
pacmanConf, color, err := initAlpm(parser.MakeArguments(), "testdata/pacman.conf")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, pacmanConf)
|
assert.NotNil(t, pacmanConf)
|
||||||
assert.Equal(t, color, false)
|
assert.Equal(t, color, false)
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/Jguer/yay/v10/pkg/db"
|
"github.com/Jguer/yay/v10/pkg/db"
|
||||||
"github.com/Jguer/yay/v10/pkg/query"
|
"github.com/Jguer/yay/v10/pkg/query"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
@ -82,7 +83,7 @@ func makePool(dbExecutor db.Executor, aurClient *aur.Client) *Pool {
|
|||||||
|
|
||||||
// Includes db/ prefixes and group installs
|
// Includes db/ prefixes and group installs
|
||||||
func (dp *Pool) ResolveTargets(pkgs []string,
|
func (dp *Pool) ResolveTargets(pkgs []string,
|
||||||
mode settings.TargetMode,
|
mode parser.TargetMode,
|
||||||
ignoreProviders, noConfirm, provides bool, rebuild string, splitN int, noDeps, noCheckDeps bool, assumeInstalled []string) error {
|
ignoreProviders, noConfirm, provides bool, rebuild string, splitN int, noDeps, noCheckDeps bool, assumeInstalled []string) error {
|
||||||
// RPC requests are slow
|
// RPC requests are slow
|
||||||
// Combine as many AUR package requests as possible into a single RPC call
|
// Combine as many AUR package requests as possible into a single RPC call
|
||||||
@ -105,7 +106,7 @@ func (dp *Pool) ResolveTargets(pkgs []string,
|
|||||||
var foundPkg db.IPackage
|
var foundPkg db.IPackage
|
||||||
|
|
||||||
// aur/ prefix means we only check the aur
|
// aur/ prefix means we only check the aur
|
||||||
if target.DB == "aur" || mode == settings.ModeAUR {
|
if target.DB == "aur" || mode == parser.ModeAUR {
|
||||||
dp.Targets = append(dp.Targets, target)
|
dp.Targets = append(dp.Targets, target)
|
||||||
aurTargets.Set(target.DepString())
|
aurTargets.Set(target.DepString())
|
||||||
continue
|
continue
|
||||||
@ -150,7 +151,7 @@ func (dp *Pool) ResolveTargets(pkgs []string,
|
|||||||
dp.Targets = append(dp.Targets, target)
|
dp.Targets = append(dp.Targets, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(aurTargets) > 0 && (mode == settings.ModeAny || mode == settings.ModeAUR) {
|
if len(aurTargets) > 0 && (mode == parser.ModeAny || mode == parser.ModeAUR) {
|
||||||
return dp.resolveAURPackages(aurTargets, true, ignoreProviders, noConfirm, provides, rebuild, splitN, noDeps, noCheckDeps)
|
return dp.resolveAURPackages(aurTargets, true, ignoreProviders, noConfirm, provides, rebuild, splitN, noDeps, noCheckDeps)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +375,7 @@ func GetPool(pkgs []string,
|
|||||||
warnings *query.AURWarnings,
|
warnings *query.AURWarnings,
|
||||||
dbExecutor db.Executor,
|
dbExecutor db.Executor,
|
||||||
aurClient *aur.Client,
|
aurClient *aur.Client,
|
||||||
mode settings.TargetMode,
|
mode parser.TargetMode,
|
||||||
ignoreProviders, noConfirm, provides bool,
|
ignoreProviders, noConfirm, provides bool,
|
||||||
rebuild string, splitN int, noDeps bool, noCheckDeps bool, assumeInstalled []string) (*Pool, error) {
|
rebuild string, splitN int, noDeps bool, noCheckDeps bool, assumeInstalled []string) (*Pool, error) {
|
||||||
dp := makePool(dbExecutor, aurClient)
|
dp := makePool(dbExecutor, aurClient)
|
||||||
|
|||||||
@ -12,8 +12,8 @@ import (
|
|||||||
|
|
||||||
"github.com/Jguer/yay/v10/pkg/db"
|
"github.com/Jguer/yay/v10/pkg/db"
|
||||||
"github.com/Jguer/yay/v10/pkg/multierror"
|
"github.com/Jguer/yay/v10/pkg/multierror"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
|
||||||
"github.com/Jguer/yay/v10/pkg/settings/exe"
|
"github.com/Jguer/yay/v10/pkg/settings/exe"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ func getURLName(pkg db.IPackage) string {
|
|||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
func PKGBUILDs(dbExecutor DBSearcher, httpClient *http.Client, targets []string, mode settings.TargetMode) (map[string][]byte, error) {
|
func PKGBUILDs(dbExecutor DBSearcher, httpClient *http.Client, targets []string, mode parser.TargetMode) (map[string][]byte, error) {
|
||||||
pkgbuilds := make(map[string][]byte, len(targets))
|
pkgbuilds := make(map[string][]byte, len(targets))
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -128,7 +128,7 @@ func PKGBUILDs(dbExecutor DBSearcher, httpClient *http.Client, targets []string,
|
|||||||
func PKGBUILDRepos(dbExecutor DBSearcher,
|
func PKGBUILDRepos(dbExecutor DBSearcher,
|
||||||
cmdRunner exe.Runner,
|
cmdRunner exe.Runner,
|
||||||
cmdBuilder exe.GitCmdBuilder,
|
cmdBuilder exe.GitCmdBuilder,
|
||||||
targets []string, mode settings.TargetMode, aurURL, dest string, force bool) (map[string]bool, error) {
|
targets []string, mode parser.TargetMode, aurURL, dest string, force bool) (map[string]bool, error) {
|
||||||
cloned := make(map[string]bool, len(targets))
|
cloned := make(map[string]bool, len(targets))
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -189,11 +189,12 @@ func PKGBUILDRepos(dbExecutor DBSearcher,
|
|||||||
return cloned, errs.Return()
|
return cloned, errs.Return()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPackageUsableName(dbExecutor DBSearcher, target string, mode settings.TargetMode) (dbname, pkgname string, aur, toSkip bool) {
|
// TODO: replace with dep.ResolveTargets
|
||||||
|
func getPackageUsableName(dbExecutor DBSearcher, target string, mode parser.TargetMode) (dbname, pkgname string, aur, toSkip bool) {
|
||||||
aur = true
|
aur = true
|
||||||
|
|
||||||
dbName, name := text.SplitDBFromName(target)
|
dbName, name := text.SplitDBFromName(target)
|
||||||
if dbName != "aur" && (mode == settings.ModeAny || mode == settings.ModeRepo) {
|
if dbName != "aur" && (mode == parser.ModeAny || mode == parser.ModeRepo) {
|
||||||
var pkg alpm.IPackage
|
var pkg alpm.IPackage
|
||||||
if dbName != "" {
|
if dbName != "" {
|
||||||
pkg = dbExecutor.SatisfierFromDB(name, dbName)
|
pkg = dbExecutor.SatisfierFromDB(name, dbName)
|
||||||
@ -214,7 +215,7 @@ func getPackageUsableName(dbExecutor DBSearcher, target string, mode settings.Ta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if aur && mode == settings.ModeRepo {
|
if aur && mode == parser.ModeRepo {
|
||||||
return dbName, name, aur, true
|
return dbName, name, aur, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
|
|
||||||
"github.com/Jguer/yay/v10/pkg/db"
|
"github.com/Jguer/yay/v10/pkg/db"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,18 +35,18 @@ func GetRemotePackages(dbExecutor db.Executor) (
|
|||||||
return remote, remoteNames
|
return remote, remoteNames
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveInvalidTargets(targets []string, mode settings.TargetMode) []string {
|
func RemoveInvalidTargets(targets []string, mode parser.TargetMode) []string {
|
||||||
filteredTargets := make([]string, 0)
|
filteredTargets := make([]string, 0)
|
||||||
|
|
||||||
for _, target := range targets {
|
for _, target := range targets {
|
||||||
dbName, _ := text.SplitDBFromName(target)
|
dbName, _ := text.SplitDBFromName(target)
|
||||||
|
|
||||||
if dbName == "aur" && mode == settings.ModeRepo {
|
if dbName == "aur" && mode == parser.ModeRepo {
|
||||||
text.Warnln(gotext.Get("%s: can't use target with option --repo -- skipping", text.Cyan(target)))
|
text.Warnln(gotext.Get("%s: can't use target with option --repo -- skipping", text.Cyan(target)))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if dbName != "aur" && dbName != "" && mode == settings.ModeAUR {
|
if dbName != "aur" && dbName != "" && mode == parser.ModeAUR {
|
||||||
text.Warnln(gotext.Get("%s: can't use target with option --aur -- skipping", text.Cyan(target)))
|
text.Warnln(gotext.Get("%s: can't use target with option --aur -- skipping", text.Cyan(target)))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
193
pkg/settings/args.go
Normal file
193
pkg/settings/args.go
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
package settings
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Configuration) ParseCommandLine(a *parser.Arguments) error {
|
||||||
|
if err := a.Parse(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.extractYayOptions(a)
|
||||||
|
|
||||||
|
cmdBuilder := c.Runtime.CmdBuilder
|
||||||
|
cmdBuilder.GitBin = c.GitBin
|
||||||
|
cmdBuilder.GitFlags = strings.Fields(c.GitFlags)
|
||||||
|
cmdBuilder.MakepkgFlags = strings.Fields(c.MFlags)
|
||||||
|
cmdBuilder.MakepkgConfPath = c.MakepkgConf
|
||||||
|
cmdBuilder.MakepkgBin = c.MakepkgBin
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Configuration) extractYayOptions(a *parser.Arguments) {
|
||||||
|
for option, value := range a.Options {
|
||||||
|
if c.handleOption(option, value.First()) {
|
||||||
|
a.DelArg(option)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Runtime.AURClient.BaseURL = strings.TrimRight(c.AURURL, "/") + "/rpc.php?"
|
||||||
|
c.AURURL = strings.TrimRight(c.AURURL, "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Configuration) handleOption(option, value string) bool {
|
||||||
|
switch option {
|
||||||
|
case "aururl":
|
||||||
|
c.AURURL = value
|
||||||
|
case "save":
|
||||||
|
c.Runtime.SaveConfig = true
|
||||||
|
case "afterclean", "cleanafter":
|
||||||
|
c.CleanAfter = true
|
||||||
|
case "noafterclean", "nocleanafter":
|
||||||
|
c.CleanAfter = false
|
||||||
|
case "devel":
|
||||||
|
c.Devel = true
|
||||||
|
case "nodevel":
|
||||||
|
c.Devel = false
|
||||||
|
case "timeupdate":
|
||||||
|
c.TimeUpdate = true
|
||||||
|
case "notimeupdate":
|
||||||
|
c.TimeUpdate = false
|
||||||
|
case "topdown":
|
||||||
|
c.SortMode = TopDown
|
||||||
|
case "bottomup":
|
||||||
|
c.SortMode = BottomUp
|
||||||
|
case "completioninterval":
|
||||||
|
n, err := strconv.Atoi(value)
|
||||||
|
if err == nil {
|
||||||
|
c.CompletionInterval = n
|
||||||
|
}
|
||||||
|
case "sortby":
|
||||||
|
c.SortBy = value
|
||||||
|
case "searchby":
|
||||||
|
c.SearchBy = value
|
||||||
|
case "noconfirm":
|
||||||
|
NoConfirm = true
|
||||||
|
case "config":
|
||||||
|
c.PacmanConf = value
|
||||||
|
case "redownload":
|
||||||
|
c.ReDownload = "yes"
|
||||||
|
case "redownloadall":
|
||||||
|
c.ReDownload = "all"
|
||||||
|
case "noredownload":
|
||||||
|
c.ReDownload = "no"
|
||||||
|
case "rebuild":
|
||||||
|
c.ReBuild = "yes"
|
||||||
|
case "rebuildall":
|
||||||
|
c.ReBuild = "all"
|
||||||
|
case "rebuildtree":
|
||||||
|
c.ReBuild = "tree"
|
||||||
|
case "norebuild":
|
||||||
|
c.ReBuild = "no"
|
||||||
|
case "batchinstall":
|
||||||
|
c.BatchInstall = true
|
||||||
|
case "nobatchinstall":
|
||||||
|
c.BatchInstall = false
|
||||||
|
case "answerclean":
|
||||||
|
c.AnswerClean = value
|
||||||
|
case "noanswerclean":
|
||||||
|
c.AnswerClean = ""
|
||||||
|
case "answerdiff":
|
||||||
|
c.AnswerDiff = value
|
||||||
|
case "noanswerdiff":
|
||||||
|
c.AnswerDiff = ""
|
||||||
|
case "answeredit":
|
||||||
|
c.AnswerEdit = value
|
||||||
|
case "noansweredit":
|
||||||
|
c.AnswerEdit = ""
|
||||||
|
case "answerupgrade":
|
||||||
|
c.AnswerUpgrade = value
|
||||||
|
case "noanswerupgrade":
|
||||||
|
c.AnswerUpgrade = ""
|
||||||
|
case "gpgflags":
|
||||||
|
c.GpgFlags = value
|
||||||
|
case "mflags":
|
||||||
|
c.MFlags = value
|
||||||
|
case "gitflags":
|
||||||
|
c.GitFlags = value
|
||||||
|
case "builddir":
|
||||||
|
c.BuildDir = value
|
||||||
|
case "absdir":
|
||||||
|
c.ABSDir = value
|
||||||
|
case "editor":
|
||||||
|
c.Editor = value
|
||||||
|
case "editorflags":
|
||||||
|
c.EditorFlags = value
|
||||||
|
case "makepkg":
|
||||||
|
c.MakepkgBin = value
|
||||||
|
case "makepkgconf":
|
||||||
|
c.MakepkgConf = value
|
||||||
|
case "nomakepkgconf":
|
||||||
|
c.MakepkgConf = ""
|
||||||
|
case "pacman":
|
||||||
|
c.PacmanBin = value
|
||||||
|
case "git":
|
||||||
|
c.GitBin = value
|
||||||
|
case "gpg":
|
||||||
|
c.GpgBin = value
|
||||||
|
case "sudo":
|
||||||
|
c.SudoBin = value
|
||||||
|
case "sudoflags":
|
||||||
|
c.SudoFlags = value
|
||||||
|
case "requestsplitn":
|
||||||
|
n, err := strconv.Atoi(value)
|
||||||
|
if err == nil && n > 0 {
|
||||||
|
c.RequestSplitN = n
|
||||||
|
}
|
||||||
|
case "sudoloop":
|
||||||
|
c.SudoLoop = true
|
||||||
|
case "nosudoloop":
|
||||||
|
c.SudoLoop = false
|
||||||
|
case "provides":
|
||||||
|
c.Provides = true
|
||||||
|
case "noprovides":
|
||||||
|
c.Provides = false
|
||||||
|
case "pgpfetch":
|
||||||
|
c.PGPFetch = true
|
||||||
|
case "nopgpfetch":
|
||||||
|
c.PGPFetch = false
|
||||||
|
case "upgrademenu":
|
||||||
|
c.UpgradeMenu = true
|
||||||
|
case "noupgrademenu":
|
||||||
|
c.UpgradeMenu = false
|
||||||
|
case "cleanmenu":
|
||||||
|
c.CleanMenu = true
|
||||||
|
case "nocleanmenu":
|
||||||
|
c.CleanMenu = false
|
||||||
|
case "diffmenu":
|
||||||
|
c.DiffMenu = true
|
||||||
|
case "nodiffmenu":
|
||||||
|
c.DiffMenu = false
|
||||||
|
case "editmenu":
|
||||||
|
c.EditMenu = true
|
||||||
|
case "noeditmenu":
|
||||||
|
c.EditMenu = false
|
||||||
|
case "useask":
|
||||||
|
c.UseAsk = true
|
||||||
|
case "nouseask":
|
||||||
|
c.UseAsk = false
|
||||||
|
case "combinedupgrade":
|
||||||
|
c.CombinedUpgrade = true
|
||||||
|
case "nocombinedupgrade":
|
||||||
|
c.CombinedUpgrade = false
|
||||||
|
case "a", "aur":
|
||||||
|
c.Runtime.Mode = parser.ModeAUR
|
||||||
|
case "repo":
|
||||||
|
c.Runtime.Mode = parser.ModeRepo
|
||||||
|
case "removemake":
|
||||||
|
c.RemoveMake = "yes"
|
||||||
|
case "noremovemake":
|
||||||
|
c.RemoveMake = "no"
|
||||||
|
case "askremovemake":
|
||||||
|
c.RemoveMake = "ask"
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/Jguer/aur"
|
"github.com/Jguer/aur"
|
||||||
|
|
||||||
"github.com/Jguer/yay/v10/pkg/settings/exe"
|
"github.com/Jguer/yay/v10/pkg/settings/exe"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/vcs"
|
"github.com/Jguer/yay/v10/pkg/vcs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -204,7 +205,7 @@ func NewConfig(version string) (*Configuration, error) {
|
|||||||
|
|
||||||
newConfig.Runtime = &Runtime{
|
newConfig.Runtime = &Runtime{
|
||||||
ConfigPath: configPath,
|
ConfigPath: configPath,
|
||||||
Mode: ModeAny,
|
Mode: parser.ModeAny,
|
||||||
SaveConfig: false,
|
SaveConfig: false,
|
||||||
CompletionPath: filepath.Join(cacheHome, completionFileName),
|
CompletionPath: filepath.Join(cacheHome, completionFileName),
|
||||||
CmdRunner: &exe.OSRunner{},
|
CmdRunner: &exe.OSRunner{},
|
||||||
|
|||||||
109
pkg/settings/exe/cmd_builder.go
Normal file
109
pkg/settings/exe/cmd_builder.go
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package exe
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/leonelquinteros/gotext"
|
||||||
|
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GitCmdBuilder interface {
|
||||||
|
BuildGitCmd(dir string, extraArgs ...string) *exec.Cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
type CmdBuilder struct {
|
||||||
|
GitBin string
|
||||||
|
GitFlags []string
|
||||||
|
MakepkgFlags []string
|
||||||
|
MakepkgConfPath string
|
||||||
|
MakepkgBin string
|
||||||
|
SudoBin string
|
||||||
|
SudoFlags []string
|
||||||
|
PacmanBin string
|
||||||
|
PacmanConfigPath string
|
||||||
|
PacmanDBPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CmdBuilder) BuildGitCmd(dir string, extraArgs ...string) *exec.Cmd {
|
||||||
|
args := make([]string, len(c.GitFlags), len(c.GitFlags)+len(extraArgs))
|
||||||
|
copy(args, c.GitFlags)
|
||||||
|
|
||||||
|
if dir != "" {
|
||||||
|
args = append(args, "-C", dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(extraArgs) > 0 {
|
||||||
|
args = append(args, extraArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command(c.GitBin, args...)
|
||||||
|
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CmdBuilder) BuildMakepkgCmd(dir string, extraArgs ...string) *exec.Cmd {
|
||||||
|
args := make([]string, len(c.MakepkgFlags), len(c.MakepkgFlags)+len(extraArgs))
|
||||||
|
copy(args, c.MakepkgFlags)
|
||||||
|
|
||||||
|
if c.MakepkgConfPath != "" {
|
||||||
|
args = append(args, "--config", c.MakepkgConfPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(extraArgs) > 0 {
|
||||||
|
args = append(args, extraArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command(c.MakepkgBin, args...)
|
||||||
|
cmd.Dir = dir
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CmdBuilder) BuildPacmanCmd(args *parser.Arguments, mode parser.TargetMode, noConfirm bool) *exec.Cmd {
|
||||||
|
argArr := make([]string, 0, 32)
|
||||||
|
needsRoot := args.NeedRoot(mode)
|
||||||
|
|
||||||
|
if needsRoot {
|
||||||
|
argArr = append(argArr, c.SudoBin)
|
||||||
|
argArr = append(argArr, c.SudoFlags...)
|
||||||
|
}
|
||||||
|
|
||||||
|
argArr = append(argArr, c.PacmanBin)
|
||||||
|
argArr = append(argArr, args.FormatGlobals()...)
|
||||||
|
argArr = append(argArr, args.FormatArgs()...)
|
||||||
|
if noConfirm {
|
||||||
|
argArr = append(argArr, "--noconfirm")
|
||||||
|
}
|
||||||
|
|
||||||
|
argArr = append(argArr, "--config", c.PacmanConfigPath, "--")
|
||||||
|
argArr = append(argArr, args.Targets...)
|
||||||
|
|
||||||
|
if needsRoot {
|
||||||
|
waitLock(c.PacmanDBPath)
|
||||||
|
}
|
||||||
|
return exec.Command(argArr[0], argArr[1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// waitLock will lock yay checking the status of db.lck until it does not exist
|
||||||
|
func waitLock(dbPath string) {
|
||||||
|
lockDBPath := filepath.Join(dbPath, "db.lck")
|
||||||
|
if _, err := os.Stat(lockDBPath); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
text.Warnln(gotext.Get("%s is present.", lockDBPath))
|
||||||
|
text.Warn(gotext.Get("There may be another Pacman instance running. Waiting..."))
|
||||||
|
|
||||||
|
for {
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
if _, err := os.Stat(lockDBPath); err != nil {
|
||||||
|
fmt.Println()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,52 +0,0 @@
|
|||||||
package exe
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
)
|
|
||||||
|
|
||||||
type GitCmdBuilder interface {
|
|
||||||
BuildGitCmd(dir string, extraArgs ...string) *exec.Cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
type CmdBuilder struct {
|
|
||||||
GitBin string
|
|
||||||
GitFlags []string
|
|
||||||
MakepkgFlags []string
|
|
||||||
MakepkgConfPath string
|
|
||||||
MakepkgBin string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *CmdBuilder) BuildGitCmd(dir string, extraArgs ...string) *exec.Cmd {
|
|
||||||
args := make([]string, len(c.GitFlags), len(c.GitFlags)+len(extraArgs))
|
|
||||||
copy(args, c.GitFlags)
|
|
||||||
|
|
||||||
if dir != "" {
|
|
||||||
args = append(args, "-C", dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(extraArgs) > 0 {
|
|
||||||
args = append(args, extraArgs...)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(c.GitBin, args...)
|
|
||||||
cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0")
|
|
||||||
return cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *CmdBuilder) BuildMakepkgCmd(dir string, extraArgs ...string) *exec.Cmd {
|
|
||||||
args := make([]string, len(c.MakepkgFlags), len(c.MakepkgFlags)+len(extraArgs))
|
|
||||||
copy(args, c.MakepkgFlags)
|
|
||||||
|
|
||||||
if c.MakepkgConfPath != "" {
|
|
||||||
args = append(args, "--config", c.MakepkgConfPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(extraArgs) > 0 {
|
|
||||||
args = append(args, extraArgs...)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(c.MakepkgBin, args...)
|
|
||||||
cmd.Dir = dir
|
|
||||||
return cmd
|
|
||||||
}
|
|
||||||
@ -1,10 +1,9 @@
|
|||||||
package settings
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
@ -101,7 +100,7 @@ func (a *Arguments) DelArg(options ...string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Arguments) NeedRoot(runtime *Runtime) bool {
|
func (a *Arguments) NeedRoot(mode TargetMode) bool {
|
||||||
if a.ExistsArg("h", "help") {
|
if a.ExistsArg("h", "help") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -146,7 +145,7 @@ func (a *Arguments) NeedRoot(runtime *Runtime) bool {
|
|||||||
if a.ExistsArg("i", "info") {
|
if a.ExistsArg("i", "info") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if a.ExistsArg("c", "clean") && runtime.Mode == ModeAUR {
|
if a.ExistsArg("c", "clean") && mode == ModeAUR {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -442,163 +441,6 @@ func isArg(arg string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleConfig(config *Configuration, option, value string) bool {
|
|
||||||
switch option {
|
|
||||||
case "aururl":
|
|
||||||
config.AURURL = value
|
|
||||||
case "save":
|
|
||||||
config.Runtime.SaveConfig = true
|
|
||||||
case "afterclean", "cleanafter":
|
|
||||||
config.CleanAfter = true
|
|
||||||
case "noafterclean", "nocleanafter":
|
|
||||||
config.CleanAfter = false
|
|
||||||
case "devel":
|
|
||||||
config.Devel = true
|
|
||||||
case "nodevel":
|
|
||||||
config.Devel = false
|
|
||||||
case "timeupdate":
|
|
||||||
config.TimeUpdate = true
|
|
||||||
case "notimeupdate":
|
|
||||||
config.TimeUpdate = false
|
|
||||||
case "topdown":
|
|
||||||
config.SortMode = TopDown
|
|
||||||
case "bottomup":
|
|
||||||
config.SortMode = BottomUp
|
|
||||||
case "completioninterval":
|
|
||||||
n, err := strconv.Atoi(value)
|
|
||||||
if err == nil {
|
|
||||||
config.CompletionInterval = n
|
|
||||||
}
|
|
||||||
case "sortby":
|
|
||||||
config.SortBy = value
|
|
||||||
case "searchby":
|
|
||||||
config.SearchBy = value
|
|
||||||
case "noconfirm":
|
|
||||||
NoConfirm = true
|
|
||||||
case "config":
|
|
||||||
config.PacmanConf = value
|
|
||||||
case "redownload":
|
|
||||||
config.ReDownload = "yes"
|
|
||||||
case "redownloadall":
|
|
||||||
config.ReDownload = "all"
|
|
||||||
case "noredownload":
|
|
||||||
config.ReDownload = "no"
|
|
||||||
case "rebuild":
|
|
||||||
config.ReBuild = "yes"
|
|
||||||
case "rebuildall":
|
|
||||||
config.ReBuild = "all"
|
|
||||||
case "rebuildtree":
|
|
||||||
config.ReBuild = "tree"
|
|
||||||
case "norebuild":
|
|
||||||
config.ReBuild = "no"
|
|
||||||
case "batchinstall":
|
|
||||||
config.BatchInstall = true
|
|
||||||
case "nobatchinstall":
|
|
||||||
config.BatchInstall = false
|
|
||||||
case "answerclean":
|
|
||||||
config.AnswerClean = value
|
|
||||||
case "noanswerclean":
|
|
||||||
config.AnswerClean = ""
|
|
||||||
case "answerdiff":
|
|
||||||
config.AnswerDiff = value
|
|
||||||
case "noanswerdiff":
|
|
||||||
config.AnswerDiff = ""
|
|
||||||
case "answeredit":
|
|
||||||
config.AnswerEdit = value
|
|
||||||
case "noansweredit":
|
|
||||||
config.AnswerEdit = ""
|
|
||||||
case "answerupgrade":
|
|
||||||
config.AnswerUpgrade = value
|
|
||||||
case "noanswerupgrade":
|
|
||||||
config.AnswerUpgrade = ""
|
|
||||||
case "gpgflags":
|
|
||||||
config.GpgFlags = value
|
|
||||||
case "mflags":
|
|
||||||
config.MFlags = value
|
|
||||||
case "gitflags":
|
|
||||||
config.GitFlags = value
|
|
||||||
case "builddir":
|
|
||||||
config.BuildDir = value
|
|
||||||
case "absdir":
|
|
||||||
config.ABSDir = value
|
|
||||||
case "editor":
|
|
||||||
config.Editor = value
|
|
||||||
case "editorflags":
|
|
||||||
config.EditorFlags = value
|
|
||||||
case "makepkg":
|
|
||||||
config.MakepkgBin = value
|
|
||||||
case "makepkgconf":
|
|
||||||
config.MakepkgConf = value
|
|
||||||
case "nomakepkgconf":
|
|
||||||
config.MakepkgConf = ""
|
|
||||||
case "pacman":
|
|
||||||
config.PacmanBin = value
|
|
||||||
case "git":
|
|
||||||
config.GitBin = value
|
|
||||||
case "gpg":
|
|
||||||
config.GpgBin = value
|
|
||||||
case "sudo":
|
|
||||||
config.SudoBin = value
|
|
||||||
case "sudoflags":
|
|
||||||
config.SudoFlags = value
|
|
||||||
case "requestsplitn":
|
|
||||||
n, err := strconv.Atoi(value)
|
|
||||||
if err == nil && n > 0 {
|
|
||||||
config.RequestSplitN = n
|
|
||||||
}
|
|
||||||
case "sudoloop":
|
|
||||||
config.SudoLoop = true
|
|
||||||
case "nosudoloop":
|
|
||||||
config.SudoLoop = false
|
|
||||||
case "provides":
|
|
||||||
config.Provides = true
|
|
||||||
case "noprovides":
|
|
||||||
config.Provides = false
|
|
||||||
case "pgpfetch":
|
|
||||||
config.PGPFetch = true
|
|
||||||
case "nopgpfetch":
|
|
||||||
config.PGPFetch = false
|
|
||||||
case "upgrademenu":
|
|
||||||
config.UpgradeMenu = true
|
|
||||||
case "noupgrademenu":
|
|
||||||
config.UpgradeMenu = false
|
|
||||||
case "cleanmenu":
|
|
||||||
config.CleanMenu = true
|
|
||||||
case "nocleanmenu":
|
|
||||||
config.CleanMenu = false
|
|
||||||
case "diffmenu":
|
|
||||||
config.DiffMenu = true
|
|
||||||
case "nodiffmenu":
|
|
||||||
config.DiffMenu = false
|
|
||||||
case "editmenu":
|
|
||||||
config.EditMenu = true
|
|
||||||
case "noeditmenu":
|
|
||||||
config.EditMenu = false
|
|
||||||
case "useask":
|
|
||||||
config.UseAsk = true
|
|
||||||
case "nouseask":
|
|
||||||
config.UseAsk = false
|
|
||||||
case "combinedupgrade":
|
|
||||||
config.CombinedUpgrade = true
|
|
||||||
case "nocombinedupgrade":
|
|
||||||
config.CombinedUpgrade = false
|
|
||||||
case "a", "aur":
|
|
||||||
config.Runtime.Mode = ModeAUR
|
|
||||||
case "repo":
|
|
||||||
config.Runtime.Mode = ModeRepo
|
|
||||||
case "removemake":
|
|
||||||
config.RemoveMake = "yes"
|
|
||||||
case "noremovemake":
|
|
||||||
config.RemoveMake = "no"
|
|
||||||
case "askremovemake":
|
|
||||||
config.RemoveMake = "ask"
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func isOp(op string) bool {
|
func isOp(op string) bool {
|
||||||
switch op {
|
switch op {
|
||||||
case "V", "version":
|
case "V", "version":
|
||||||
@ -759,7 +601,7 @@ func (a *Arguments) parseStdin() error {
|
|||||||
return os.Stdin.Close()
|
return os.Stdin.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Arguments) ParseCommandLine(config *Configuration) error {
|
func (a *Arguments) Parse() error {
|
||||||
args := os.Args[1:]
|
args := os.Args[1:]
|
||||||
usedNext := false
|
usedNext := false
|
||||||
|
|
||||||
@ -816,25 +658,5 @@ func (a *Arguments) ParseCommandLine(config *Configuration) error {
|
|||||||
os.Stdin = file
|
os.Stdin = file
|
||||||
}
|
}
|
||||||
|
|
||||||
a.extractYayOptions(config)
|
|
||||||
|
|
||||||
cmdBuilder := config.Runtime.CmdBuilder
|
|
||||||
cmdBuilder.GitBin = config.GitBin
|
|
||||||
cmdBuilder.GitFlags = strings.Fields(config.GitFlags)
|
|
||||||
cmdBuilder.MakepkgFlags = strings.Fields(config.MFlags)
|
|
||||||
cmdBuilder.MakepkgConfPath = config.MakepkgConf
|
|
||||||
cmdBuilder.MakepkgBin = config.MakepkgBin
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Arguments) extractYayOptions(config *Configuration) {
|
|
||||||
for option, value := range a.Options {
|
|
||||||
if handleConfig(config, option, value.First()) {
|
|
||||||
a.DelArg(option)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config.Runtime.AURClient.BaseURL = strings.TrimRight(config.AURURL, "/") + "/rpc.php?"
|
|
||||||
config.AURURL = strings.TrimRight(config.AURURL, "/")
|
|
||||||
}
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package settings
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
9
pkg/settings/parser/target_mode.go
Normal file
9
pkg/settings/parser/target_mode.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
type TargetMode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
ModeAny TargetMode = iota
|
||||||
|
ModeAUR
|
||||||
|
ModeRepo
|
||||||
|
)
|
||||||
@ -8,19 +8,12 @@ import (
|
|||||||
"github.com/Jguer/aur"
|
"github.com/Jguer/aur"
|
||||||
|
|
||||||
"github.com/Jguer/yay/v10/pkg/settings/exe"
|
"github.com/Jguer/yay/v10/pkg/settings/exe"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/vcs"
|
"github.com/Jguer/yay/v10/pkg/vcs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TargetMode int
|
|
||||||
|
|
||||||
const (
|
|
||||||
ModeAny TargetMode = iota
|
|
||||||
ModeAUR
|
|
||||||
ModeRepo
|
|
||||||
)
|
|
||||||
|
|
||||||
type Runtime struct {
|
type Runtime struct {
|
||||||
Mode TargetMode
|
Mode parser.TargetMode
|
||||||
SaveConfig bool
|
SaveConfig bool
|
||||||
CompletionPath string
|
CompletionPath string
|
||||||
ConfigPath string
|
ConfigPath string
|
||||||
|
|||||||
3
print.go
3
print.go
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/Jguer/yay/v10/pkg/db"
|
"github.com/Jguer/yay/v10/pkg/db"
|
||||||
"github.com/Jguer/yay/v10/pkg/query"
|
"github.com/Jguer/yay/v10/pkg/query"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
"github.com/Jguer/yay/v10/pkg/upgrade"
|
"github.com/Jguer/yay/v10/pkg/upgrade"
|
||||||
@ -196,7 +197,7 @@ func printNumberOfUpdates(dbExecutor db.Executor, enableDowngrade bool, filter u
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make it less hacky
|
// TODO: Make it less hacky
|
||||||
func printUpdateList(cmdArgs *settings.Arguments, dbExecutor db.Executor, enableDowngrade bool, filter upgrade.Filter) error {
|
func printUpdateList(cmdArgs *parser.Arguments, dbExecutor db.Executor, enableDowngrade bool, filter upgrade.Filter) error {
|
||||||
targets := stringset.FromSlice(cmdArgs.Targets)
|
targets := stringset.FromSlice(cmdArgs.Targets)
|
||||||
warnings := query.NewWarnings()
|
warnings := query.NewWarnings()
|
||||||
old := os.Stdout // keep backup of the real stdout
|
old := os.Stdout // keep backup of the real stdout
|
||||||
|
|||||||
19
query.go
19
query.go
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/Jguer/yay/v10/pkg/db"
|
"github.com/Jguer/yay/v10/pkg/db"
|
||||||
"github.com/Jguer/yay/v10/pkg/query"
|
"github.com/Jguer/yay/v10/pkg/query"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings"
|
||||||
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
)
|
)
|
||||||
@ -154,26 +155,26 @@ func syncSearch(pkgS []string, aurClient *aur.Client, dbExecutor db.Executor) (e
|
|||||||
var aq aurQuery
|
var aq aurQuery
|
||||||
var pq repoQuery
|
var pq repoQuery
|
||||||
|
|
||||||
if config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||||
aq, aurErr = narrowSearch(aurClient, pkgS, true)
|
aq, aurErr = narrowSearch(aurClient, pkgS, true)
|
||||||
}
|
}
|
||||||
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||||
pq = queryRepo(pkgS, dbExecutor)
|
pq = queryRepo(pkgS, dbExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch config.SortMode {
|
switch config.SortMode {
|
||||||
case settings.TopDown:
|
case settings.TopDown:
|
||||||
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||||
pq.printSearch(dbExecutor)
|
pq.printSearch(dbExecutor)
|
||||||
}
|
}
|
||||||
if config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||||
aq.printSearch(1, dbExecutor)
|
aq.printSearch(1, dbExecutor)
|
||||||
}
|
}
|
||||||
case settings.BottomUp:
|
case settings.BottomUp:
|
||||||
if config.Runtime.Mode == settings.ModeAUR || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeAUR || config.Runtime.Mode == parser.ModeAny {
|
||||||
aq.printSearch(1, dbExecutor)
|
aq.printSearch(1, dbExecutor)
|
||||||
}
|
}
|
||||||
if config.Runtime.Mode == settings.ModeRepo || config.Runtime.Mode == settings.ModeAny {
|
if config.Runtime.Mode == parser.ModeRepo || config.Runtime.Mode == parser.ModeAny {
|
||||||
pq.printSearch(dbExecutor)
|
pq.printSearch(dbExecutor)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -189,7 +190,7 @@ func syncSearch(pkgS []string, aurClient *aur.Client, dbExecutor db.Executor) (e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SyncInfo serves as a pacman -Si for repo packages and AUR packages.
|
// SyncInfo serves as a pacman -Si for repo packages and AUR packages.
|
||||||
func syncInfo(cmdArgs *settings.Arguments, pkgS []string, dbExecutor db.Executor) error {
|
func syncInfo(cmdArgs *parser.Arguments, pkgS []string, dbExecutor db.Executor) error {
|
||||||
var info []*aur.Pkg
|
var info []*aur.Pkg
|
||||||
var err error
|
var err error
|
||||||
missing := false
|
missing := false
|
||||||
@ -255,10 +256,10 @@ func packageSlices(toCheck []string, dbExecutor db.Executor) (aurNames, repoName
|
|||||||
for _, _pkg := range toCheck {
|
for _, _pkg := range toCheck {
|
||||||
dbName, name := text.SplitDBFromName(_pkg)
|
dbName, name := text.SplitDBFromName(_pkg)
|
||||||
|
|
||||||
if dbName == "aur" || config.Runtime.Mode == settings.ModeAUR {
|
if dbName == "aur" || config.Runtime.Mode == parser.ModeAUR {
|
||||||
aurNames = append(aurNames, _pkg)
|
aurNames = append(aurNames, _pkg)
|
||||||
continue
|
continue
|
||||||
} else if dbName != "" || config.Runtime.Mode == settings.ModeRepo {
|
} else if dbName != "" || config.Runtime.Mode == parser.ModeRepo {
|
||||||
repoNames = append(repoNames, _pkg)
|
repoNames = append(repoNames, _pkg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/Jguer/yay/v10/pkg/intrange"
|
"github.com/Jguer/yay/v10/pkg/intrange"
|
||||||
"github.com/Jguer/yay/v10/pkg/multierror"
|
"github.com/Jguer/yay/v10/pkg/multierror"
|
||||||
"github.com/Jguer/yay/v10/pkg/query"
|
"github.com/Jguer/yay/v10/pkg/query"
|
||||||
"github.com/Jguer/yay/v10/pkg/settings"
|
"github.com/Jguer/yay/v10/pkg/settings/parser"
|
||||||
"github.com/Jguer/yay/v10/pkg/stringset"
|
"github.com/Jguer/yay/v10/pkg/stringset"
|
||||||
"github.com/Jguer/yay/v10/pkg/text"
|
"github.com/Jguer/yay/v10/pkg/text"
|
||||||
"github.com/Jguer/yay/v10/pkg/upgrade"
|
"github.com/Jguer/yay/v10/pkg/upgrade"
|
||||||
@ -48,7 +48,7 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Runtime.Mode == settings.ModeAny || config.Runtime.Mode == settings.ModeRepo {
|
if config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeRepo {
|
||||||
text.OperationInfoln(gotext.Get("Searching databases for updates..."))
|
text.OperationInfoln(gotext.Get("Searching databases for updates..."))
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
@ -58,7 +58,7 @@ func upList(warnings *query.AURWarnings, dbExecutor db.Executor, enableDowngrade
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Runtime.Mode == settings.ModeAny || config.Runtime.Mode == settings.ModeAUR {
|
if config.Runtime.Mode == parser.ModeAny || config.Runtime.Mode == parser.ModeAUR {
|
||||||
text.OperationInfoln(gotext.Get("Searching AUR for updates..."))
|
text.OperationInfoln(gotext.Get("Searching AUR for updates..."))
|
||||||
|
|
||||||
var _aurdata []*aur.Pkg
|
var _aurdata []*aur.Pkg
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user