mirror of
https://github.com/Jguer/yay
synced 2024-10-31 04:12:51 +00:00
Replicates the range functionally to upgrade
This commit is contained in:
parent
29cd864bbe
commit
6d2dcad091
2 changed files with 23 additions and 14 deletions
9
cmd.go
9
cmd.go
|
@ -309,7 +309,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func buildRange(input string) (numbers []int, err error) {
|
||||
func BuildRange(input string) (numbers []int, err error) {
|
||||
multipleNums := strings.Split(input, "-")
|
||||
if len(multipleNums) != 2 {
|
||||
return nil, errors.New("Invalid range")
|
||||
|
@ -367,8 +367,9 @@ func numberMenu(pkgS []string, flags []string) (err error) {
|
|||
aq.printSearch(numpq + 1)
|
||||
}
|
||||
|
||||
fmt.Printf("\x1b[32m%s\x1b[0m\nNumbers: ",
|
||||
"Type numbers to install. Separate each number with a space.")
|
||||
fmt.Printf("\x1b[32m%s %s\x1b[0m\nNumbers: ",
|
||||
"Type the numbers or ranges (e.g. 1-10) you want to install.",
|
||||
"Separate each one of them with a space.")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
numberBuf, overflow, err := reader.ReadLine()
|
||||
if err != nil || overflow {
|
||||
|
@ -384,7 +385,7 @@ func numberMenu(pkgS []string, flags []string) (err error) {
|
|||
var numbers []int
|
||||
num, err = strconv.Atoi(numS)
|
||||
if err != nil {
|
||||
numbers, err = buildRange(numS)
|
||||
numbers, err = BuildRange(numS)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
28
upgrade.go
28
upgrade.go
|
@ -279,7 +279,7 @@ func upgradePkgs(flags []string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
} else if len(aurUp)+len(repoUp) == 0 {
|
||||
fmt.Println("\nthere is nothing to do")
|
||||
fmt.Println("\nThere is nothing to do")
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -302,18 +302,26 @@ func upgradePkgs(flags []string) error {
|
|||
|
||||
result := strings.Fields(string(numberBuf))
|
||||
for _, numS := range result {
|
||||
var numbers []int
|
||||
num, err := strconv.Atoi(numS)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if num > len(aurUp)+len(repoUp)-1 || num < 0 {
|
||||
continue
|
||||
} else if num < len(aurUp) {
|
||||
num = len(aurUp) - num - 1
|
||||
aurNums = append(aurNums, num)
|
||||
numbers, err = BuildRange(numS)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
num = len(aurUp) + len(repoUp) - num - 1
|
||||
repoNums = append(repoNums, num)
|
||||
numbers = []int{num}
|
||||
}
|
||||
for _, target := range numbers {
|
||||
if target > len(aurUp)+len(repoUp)-1 || target < 0 {
|
||||
continue
|
||||
} else if target < len(aurUp) {
|
||||
target = len(aurUp) - target - 1
|
||||
aurNums = append(aurNums, target)
|
||||
} else {
|
||||
target = len(aurUp) + len(repoUp) - target - 1
|
||||
repoNums = append(repoNums, target)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue