mirror of
https://github.com/Jguer/yay.git
synced 2025-10-04 00:03:11 -04:00
Add flags for sort order and automating menu input
Added: --sortby <votes|popularity|id|baseid|name|base|submitted|modified> --answerclean --answeredit --answerupgrade --noanswerclean --noansweredit --noanswerupgrade TODO: docs and completion
This commit is contained in:
parent
794e8dd3c7
commit
8556acdd5f
14
cmd.go
14
cmd.go
@ -214,6 +214,8 @@ func handleConfig(option, value string) bool {
|
|||||||
config.SortMode = TopDown
|
config.SortMode = TopDown
|
||||||
case "bottomup":
|
case "bottomup":
|
||||||
config.SortMode = BottomUp
|
config.SortMode = BottomUp
|
||||||
|
case "sortby":
|
||||||
|
config.SortBy = value
|
||||||
case "noconfirm":
|
case "noconfirm":
|
||||||
config.NoConfirm = true
|
config.NoConfirm = true
|
||||||
case "redownload":
|
case "redownload":
|
||||||
@ -230,6 +232,18 @@ func handleConfig(option, value string) bool {
|
|||||||
config.ReBuild = "tree"
|
config.ReBuild = "tree"
|
||||||
case "norebuild":
|
case "norebuild":
|
||||||
config.ReBuild = "no"
|
config.ReBuild = "no"
|
||||||
|
case "answerclean":
|
||||||
|
config.AnswerClean = value
|
||||||
|
case "noanswerclean":
|
||||||
|
config.AnswerClean = ""
|
||||||
|
case "answeredit":
|
||||||
|
config.AnswerEdit = value
|
||||||
|
case "noansweredit":
|
||||||
|
config.AnswerEdit = ""
|
||||||
|
case "answerupgrade":
|
||||||
|
config.AnswerUpgrade = value
|
||||||
|
case "noanswerupgrade":
|
||||||
|
config.AnswerUpgrade = ""
|
||||||
case "gpgflags":
|
case "gpgflags":
|
||||||
config.GpgFlags = value
|
config.GpgFlags = value
|
||||||
case "mflags":
|
case "mflags":
|
||||||
|
29
config.go
29
config.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -33,10 +34,14 @@ type Configuration struct {
|
|||||||
TarBin string `json:"tarbin"`
|
TarBin string `json:"tarbin"`
|
||||||
ReDownload string `json:"redownload"`
|
ReDownload string `json:"redownload"`
|
||||||
ReBuild string `json:"rebuild"`
|
ReBuild string `json:"rebuild"`
|
||||||
|
AnswerClean string `json:"answerclean"`
|
||||||
|
AnswerEdit string `json:"answeredit"`
|
||||||
|
AnswerUpgrade string `json:"answerupgrade"`
|
||||||
GitBin string `json:"gitbin"`
|
GitBin string `json:"gitbin"`
|
||||||
GpgBin string `json:"gpgbin"`
|
GpgBin string `json:"gpgbin"`
|
||||||
GpgFlags string `json:"gpgflags"`
|
GpgFlags string `json:"gpgflags"`
|
||||||
MFlags string `json:"mflags"`
|
MFlags string `json:"mflags"`
|
||||||
|
SortBy string `json:"sortby"`
|
||||||
RequestSplitN int `json:"requestsplitn"`
|
RequestSplitN int `json:"requestsplitn"`
|
||||||
SearchMode int `json:"-"`
|
SearchMode int `json:"-"`
|
||||||
SortMode int `json:"sortmode"`
|
SortMode int `json:"sortmode"`
|
||||||
@ -134,6 +139,7 @@ func defaultSettings(config *Configuration) {
|
|||||||
config.GpgFlags = ""
|
config.GpgFlags = ""
|
||||||
config.MFlags = ""
|
config.MFlags = ""
|
||||||
config.SortMode = BottomUp
|
config.SortMode = BottomUp
|
||||||
|
config.SortBy = "votes"
|
||||||
config.SudoLoop = false
|
config.SudoLoop = false
|
||||||
config.TarBin = "bsdtar"
|
config.TarBin = "bsdtar"
|
||||||
config.GitBin = "git"
|
config.GitBin = "git"
|
||||||
@ -142,6 +148,9 @@ func defaultSettings(config *Configuration) {
|
|||||||
config.RequestSplitN = 150
|
config.RequestSplitN = 150
|
||||||
config.ReDownload = "no"
|
config.ReDownload = "no"
|
||||||
config.ReBuild = "no"
|
config.ReBuild = "no"
|
||||||
|
config.AnswerClean = ""
|
||||||
|
config.AnswerEdit = ""
|
||||||
|
config.AnswerUpgrade = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Editor returns the preferred system editor.
|
// Editor returns the preferred system editor.
|
||||||
@ -223,6 +232,26 @@ func continueTask(s string, def string) (cont bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getInput(defaultValue string) (string, error) {
|
||||||
|
if defaultValue != "" {
|
||||||
|
fmt.Println(defaultValue)
|
||||||
|
return defaultValue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
|
buf, overflow, err := reader.ReadLine()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if overflow {
|
||||||
|
return "", fmt.Errorf("Input too long")
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(buf), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (config Configuration) String() string {
|
func (config Configuration) String() string {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
enc := json.NewEncoder(&buf)
|
enc := json.NewEncoder(&buf)
|
||||||
|
20
install.go
20
install.go
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -337,19 +336,11 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
|
|||||||
fmt.Println(bold(green(arrow + " Packages to cleanBuild?")))
|
fmt.Println(bold(green(arrow + " Packages to cleanBuild?")))
|
||||||
fmt.Println(bold(green(arrow) + cyan(" [N]one ") + green("[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)")))
|
fmt.Println(bold(green(arrow) + cyan(" [N]one ") + green("[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)")))
|
||||||
fmt.Print(bold(green(arrow + " ")))
|
fmt.Print(bold(green(arrow + " ")))
|
||||||
reader := bufio.NewReader(os.Stdin)
|
cleanInput, err := getInput(config.AnswerClean)
|
||||||
|
|
||||||
numberBuf, overflow, err := reader.ReadLine()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if overflow {
|
|
||||||
return nil, nil, fmt.Errorf("Input too long")
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanInput := string(numberBuf)
|
|
||||||
|
|
||||||
cInclude, cExclude, cOtherInclude, cOtherExclude := parseNumberMenu(cleanInput)
|
cInclude, cExclude, cOtherInclude, cOtherExclude := parseNumberMenu(cleanInput)
|
||||||
cIsInclude := len(cExclude) == 0 && len(cOtherExclude) == 0
|
cIsInclude := len(cExclude) == 0 && len(cOtherExclude) == 0
|
||||||
|
|
||||||
@ -398,19 +389,12 @@ func cleanEditNumberMenu(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, installed
|
|||||||
fmt.Println(bold(green(arrow) + cyan(" [N]one ") + green("[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)")))
|
fmt.Println(bold(green(arrow) + cyan(" [N]one ") + green("[A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)")))
|
||||||
|
|
||||||
fmt.Print(bold(green(arrow + " ")))
|
fmt.Print(bold(green(arrow + " ")))
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
|
|
||||||
numberBuf, overflow, err := reader.ReadLine()
|
editInput, err := getInput(config.AnswerEdit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if overflow {
|
|
||||||
return nil, nil, fmt.Errorf("Input too long")
|
|
||||||
}
|
|
||||||
|
|
||||||
editInput := string(numberBuf)
|
|
||||||
|
|
||||||
eInclude, eExclude, eOtherInclude, eOtherExclude := parseNumberMenu(editInput)
|
eInclude, eExclude, eOtherInclude, eOtherExclude := parseNumberMenu(editInput)
|
||||||
eIsInclude := len(eExclude) == 0 && len(eOtherExclude) == 0
|
eIsInclude := len(eExclude) == 0 && len(eOtherExclude) == 0
|
||||||
|
|
||||||
|
@ -445,6 +445,14 @@ func hasParam(arg string) bool {
|
|||||||
return true
|
return true
|
||||||
case "requestsplitn":
|
case "requestsplitn":
|
||||||
return true
|
return true
|
||||||
|
case "answerclean":
|
||||||
|
return true
|
||||||
|
case "answeredit":
|
||||||
|
return true
|
||||||
|
case "answerupgrade":
|
||||||
|
return true
|
||||||
|
case "sortby":
|
||||||
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
28
query.go
28
query.go
@ -21,10 +21,32 @@ func (q aurQuery) Len() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q aurQuery) Less(i, j int) bool {
|
func (q aurQuery) Less(i, j int) bool {
|
||||||
if config.SortMode == BottomUp {
|
var result bool
|
||||||
return q[i].NumVotes < q[j].NumVotes
|
|
||||||
|
switch config.SortBy {
|
||||||
|
case "votes":
|
||||||
|
result = q[i].NumVotes > q[j].NumVotes
|
||||||
|
case "popularity":
|
||||||
|
result = q[i].Popularity > q[j].Popularity
|
||||||
|
case "name":
|
||||||
|
result = lessRunes([]rune(q[i].Name), []rune(q[j].Name))
|
||||||
|
case "base":
|
||||||
|
result = lessRunes([]rune(q[i].PackageBase), []rune(q[j].PackageBase))
|
||||||
|
case "submitted":
|
||||||
|
result = q[i].FirstSubmitted < q[j].FirstSubmitted
|
||||||
|
case "modified":
|
||||||
|
result = q[i].LastModified < q[j].LastModified
|
||||||
|
case "id":
|
||||||
|
result = q[i].ID < q[j].ID
|
||||||
|
case "baseid":
|
||||||
|
result = q[i].PackageBaseID < q[j].PackageBaseID
|
||||||
}
|
}
|
||||||
return q[i].NumVotes > q[j].NumVotes
|
|
||||||
|
if config.SortMode == BottomUp {
|
||||||
|
return !result
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q aurQuery) Swap(i, j int) {
|
func (q aurQuery) Swap(i, j int) {
|
||||||
|
11
upgrade.go
11
upgrade.go
@ -1,9 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -288,21 +286,16 @@ func upgradePkgs(aurUp, repoUp upSlice) (stringSet, stringSet, error) {
|
|||||||
|
|
||||||
fmt.Println(bold(green(arrow + " Packages to not upgrade (eg: 1 2 3, 1-3, ^4 or repo name)")))
|
fmt.Println(bold(green(arrow + " Packages to not upgrade (eg: 1 2 3, 1-3, ^4 or repo name)")))
|
||||||
fmt.Print(bold(green(arrow + " ")))
|
fmt.Print(bold(green(arrow + " ")))
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
|
|
||||||
numberBuf, overflow, err := reader.ReadLine()
|
numbers, err := getInput(config.AnswerUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if overflow {
|
|
||||||
return nil, nil, fmt.Errorf("Input too long")
|
|
||||||
}
|
|
||||||
|
|
||||||
//upgrade menu asks you which packages to NOT upgrade so in this case
|
//upgrade menu asks you which packages to NOT upgrade so in this case
|
||||||
//include and exclude are kind of swaped
|
//include and exclude are kind of swaped
|
||||||
//include, exclude, other := parseNumberMenu(string(numberBuf))
|
//include, exclude, other := parseNumberMenu(string(numberBuf))
|
||||||
include, exclude, otherInclude, otherExclude := parseNumberMenu(string(numberBuf))
|
include, exclude, otherInclude, otherExclude := parseNumberMenu(numbers)
|
||||||
|
|
||||||
isInclude := len(exclude) == 0 && len(otherExclude) == 0
|
isInclude := len(exclude) == 0 && len(otherExclude) == 0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user