Replicates the range functionally to upgrade

This commit is contained in:
Samuel Henrique Oliveira da Silva 2018-01-14 14:04:15 -02:00
parent 29cd864bbe
commit 6d2dcad091
2 changed files with 23 additions and 14 deletions

9
cmd.go
View file

@ -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
}

View file

@ -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 {
numbers, err = BuildRange(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)
} 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)
}
}
}
}