Extend aur support for -Qu

-Qu now has AUR support, it functions identically to `-Pu` and may replace
it in the futre.

Aditionally the pacman options `-n` and `-m` are also supported to
filter out native and non native packages. Other flags are not supported
currently.

Using any other `-Q` will fallback to Pacman.
This commit is contained in:
morganamilo 2018-03-21 04:50:54 +00:00
parent 44f2da3211
commit add22f5957
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 41 additions and 12 deletions

26
cmd.go
View file

@ -342,19 +342,19 @@ func handleCmd() (err error) {
case "V", "version": case "V", "version":
handleVersion() handleVersion()
case "D", "database": case "D", "database":
passToPacman(cmdArgs) err = passToPacman(cmdArgs)
case "F", "files": case "F", "files":
passToPacman(cmdArgs) err = passToPacman(cmdArgs)
case "Q", "query": case "Q", "query":
passToPacman(cmdArgs) err = handleQuery()
case "R", "remove": case "R", "remove":
handleRemove() err = handleRemove()
case "S", "sync": case "S", "sync":
err = handleSync() err = handleSync()
case "T", "deptest": case "T", "deptest":
passToPacman(cmdArgs) err = passToPacman(cmdArgs)
case "U", "upgrade": case "U", "upgrade":
passToPacman(cmdArgs) err =passToPacman(cmdArgs)
case "G", "getpkgbuild": case "G", "getpkgbuild":
err = handleGetpkgbuild() err = handleGetpkgbuild()
case "P", "print": case "P", "print":
@ -370,6 +370,18 @@ func handleCmd() (err error) {
return return
} }
func handleQuery() error {
var err error
if cmdArgs.existsArg("u", "upgrades") {
err = printUpdateList(cmdArgs)
} else {
err = passToPacman(cmdArgs)
}
return err
}
//this function should only set config options //this function should only set config options
//but currently still uses the switch left over from old code //but currently still uses the switch left over from old code
//eventually this should be refactored out futher //eventually this should be refactored out futher
@ -461,7 +473,7 @@ func handlePrint() (err error) {
case cmdArgs.existsArg("n", "numberupgrades"): case cmdArgs.existsArg("n", "numberupgrades"):
err = printNumberOfUpdates() err = printNumberOfUpdates()
case cmdArgs.existsArg("u", "upgrades"): case cmdArgs.existsArg("u", "upgrades"):
err = printUpdateList() err = printUpdateList(cmdArgs)
case cmdArgs.existsArg("c", "complete"): case cmdArgs.existsArg("c", "complete"):
switch { switch {
case cmdArgs.existsArg("f", "fish"): case cmdArgs.existsArg("f", "fish"):

View file

@ -301,7 +301,7 @@ func printNumberOfUpdates() error {
} }
//TODO: Make it less hacky //TODO: Make it less hacky
func printUpdateList() error { func printUpdateList(parser *arguments) error {
old := os.Stdout // Keep backup of the real stdout old := os.Stdout // Keep backup of the real stdout
os.Stdout = nil os.Stdout = nil
_, _, localNames, remoteNames, err := filterPackages() _, _, localNames, remoteNames, err := filterPackages()
@ -312,12 +312,29 @@ func printUpdateList() error {
if err != nil { if err != nil {
return err return err
} }
noTargets := len(parser.targets) == 0
if !parser.existsArg("m", "foreigne") {
for _, pkg := range repoUp { for _, pkg := range repoUp {
fmt.Println(pkg.Name) if noTargets || parser.targets.get(pkg.Name) {
fmt.Printf("%s %s -> %s\n", bold(pkg.Name), green(pkg.LocalVersion), green(pkg.RemoteVersion))
delete(parser.targets, pkg.Name)
}
}
} }
if !parser.existsArg("n", "native") {
for _, pkg := range aurUp { for _, pkg := range aurUp {
fmt.Println(pkg.Name) if noTargets || parser.targets.get(pkg.Name) {
fmt.Printf("%s %s -> %s\n", bold(pkg.Name), green(pkg.LocalVersion), green(pkg.RemoteVersion))
delete(parser.targets, pkg.Name)
}
}
}
for pkg := range parser.targets {
fmt.Println(red(bold("error:")), "package '" + pkg + "' was not found")
} }
return nil return nil