Support --aur and --repo flags

These flags limit operations to only check the repos or only check the
AUR. These flags apply to -S, -Si and -Su.

-a may also be used as a short option for --aur. --repo has no short
option as -r is taken.
This commit is contained in:
morganamilo 2018-05-31 16:23:15 +01:00
parent b5715de4fd
commit 0ae8fc2a06
No known key found for this signature in database
GPG Key ID: 6FE9E7996B0B082E
6 changed files with 56 additions and 24 deletions

4
cmd.go
View File

@ -300,6 +300,10 @@ func handleConfig(option, value string) bool {
config.Provides = true config.Provides = true
case "noprovides": case "noprovides":
config.Provides = false config.Provides = false
case "a", "aur":
mode = ModeAUR
case "repo":
mode = ModeRepo
default: default:
return false return false
} }

View File

@ -25,6 +25,14 @@ const (
TopDown TopDown
) )
type targetMode int
const (
ModeAUR targetMode = iota
ModeRepo
ModeAny
)
// Configuration stores yay's config. // Configuration stores yay's config.
type Configuration struct { type Configuration struct {
BuildDir string `json:"buildDir"` BuildDir string `json:"buildDir"`
@ -98,6 +106,9 @@ var alpmConf alpm.PacmanConfig
// AlpmHandle is the alpm handle used by yay. // AlpmHandle is the alpm handle used by yay.
var alpmHandle *alpm.Handle var alpmHandle *alpm.Handle
// Mode is used to restrict yay to AUR or repo only modes
var mode targetMode = ModeAny
func readAlpmConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) { func readAlpmConfig(pacmanconf string) (conf alpm.PacmanConfig, err error) {
file, err := os.Open(pacmanconf) file, err := os.Open(pacmanconf)
if err != nil { if err != nil {

View File

@ -101,12 +101,17 @@ func (dp *depPool) ResolveTargets(pkgs []string) error {
var singleDb *alpm.Db var singleDb *alpm.Db
// aur/ prefix means we only check the aur // aur/ prefix means we only check the aur
if target.Db == "aur" { if target.Db == "aur" || (target.Db == "" && mode == ModeAUR) {
dp.Targets = append(dp.Targets, target) dp.Targets = append(dp.Targets, target)
aurTargets.set(target.DepString()) aurTargets.set(target.DepString())
continue continue
} }
if mode == ModeAUR {
dp.Targets = append(dp.Targets, target)
continue
}
// if theres a different priefix only look in that repo // if theres a different priefix only look in that repo
if target.Db != "" { if target.Db != "" {
singleDb, err = alpmHandle.SyncDbByName(target.Db) singleDb, err = alpmHandle.SyncDbByName(target.Db)
@ -151,7 +156,7 @@ func (dp *depPool) ResolveTargets(pkgs []string) error {
dp.Targets = append(dp.Targets, target) dp.Targets = append(dp.Targets, target)
} }
if len(aurTargets) > 0 { if len(aurTargets) > 0 && (mode == ModeAny || mode == ModeAUR) {
return dp.resolveAURPackages(aurTargets, true) return dp.resolveAURPackages(aurTargets, true)
} }

View File

@ -49,6 +49,10 @@ func install(parser *arguments) error {
arguments.op = "S" arguments.op = "S"
arguments.targets = make(stringSet) arguments.targets = make(stringSet)
if mode == ModeAUR {
arguments.delArg("u", "sysupgrade")
}
//if we are doing -u also request all packages needing update //if we are doing -u also request all packages needing update
if parser.existsArg("u", "sysupgrade") { if parser.existsArg("u", "sysupgrade") {
aurUp, repoUp, err = upList(warnings) aurUp, repoUp, err = upList(warnings)
@ -125,7 +129,7 @@ func install(parser *arguments) error {
arguments.addTarget(pkg) arguments.addTarget(pkg)
} }
if len(do.Aur) == 0 && len(arguments.targets) == 0 && !parser.existsArg("u", "sysupgrade") { if len(do.Aur) == 0 && len(arguments.targets) == 0 && (!parser.existsArg("u", "sysupgrade") || mode == ModeAUR) {
fmt.Println("There is nothing to do") fmt.Println("There is nothing to do")
return nil return nil
} }

View File

@ -220,8 +220,8 @@ func syncInfo(pkgS []string) (err error) {
} }
} }
if len(aurS) != len(info) { if len(repoS)+len(aurS) != len(pkgS) {
return fmt.Errorf("Could not find all required packages") return fmt.Errorf("Could not find all packages")
} }
return return
@ -288,10 +288,14 @@ func packageSlices(toCheck []string) (aur []string, repo []string, err error) {
db, name := splitDbFromName(_pkg) db, name := splitDbFromName(_pkg)
found := false found := false
if db == "aur" { if db == "aur" || (mode == ModeAUR && db != "") {
continue
}
if db == "aur" || (mode == ModeAUR && db == "") {
aur = append(aur, _pkg) aur = append(aur, _pkg)
continue continue
} else if db != "" { } else if db != "" || mode == ModeRepo {
repo = append(repo, _pkg) repo = append(repo, _pkg)
continue continue
} }

View File

@ -140,13 +140,16 @@ func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) {
pkgdata := make(map[string]*rpc.Pkg) pkgdata := make(map[string]*rpc.Pkg)
if mode == ModeAny || mode == ModeRepo {
fmt.Println(bold(cyan("::") + bold(" Searching databases for updates..."))) fmt.Println(bold(cyan("::") + bold(" Searching databases for updates...")))
wg.Add(1) wg.Add(1)
go func() { go func() {
repoUp, repoErr = upRepo(local) repoUp, repoErr = upRepo(local)
wg.Done() wg.Done()
}() }()
}
if mode == ModeAny || mode == ModeAUR {
fmt.Println(bold(cyan("::") + bold(" Searching AUR for updates..."))) fmt.Println(bold(cyan("::") + bold(" Searching AUR for updates...")))
wg.Add(1) wg.Add(1)
go func() { go func() {
@ -162,6 +165,7 @@ func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) {
wg.Done() wg.Done()
}() }()
} }
}
wg.Wait() wg.Wait()