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, "-") multipleNums := strings.Split(input, "-")
if len(multipleNums) != 2 { if len(multipleNums) != 2 {
return nil, errors.New("Invalid range") return nil, errors.New("Invalid range")
@ -367,8 +367,9 @@ func numberMenu(pkgS []string, flags []string) (err error) {
aq.printSearch(numpq + 1) aq.printSearch(numpq + 1)
} }
fmt.Printf("\x1b[32m%s\x1b[0m\nNumbers: ", fmt.Printf("\x1b[32m%s %s\x1b[0m\nNumbers: ",
"Type numbers to install. Separate each number with a space.") "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) reader := bufio.NewReader(os.Stdin)
numberBuf, overflow, err := reader.ReadLine() numberBuf, overflow, err := reader.ReadLine()
if err != nil || overflow { if err != nil || overflow {
@ -384,7 +385,7 @@ func numberMenu(pkgS []string, flags []string) (err error) {
var numbers []int var numbers []int
num, err = strconv.Atoi(numS) num, err = strconv.Atoi(numS)
if err != nil { if err != nil {
numbers, err = buildRange(numS) numbers, err = BuildRange(numS)
if err != nil { if err != nil {
continue continue
} }

View file

@ -279,7 +279,7 @@ func upgradePkgs(flags []string) error {
if err != nil { if err != nil {
return err return err
} else if len(aurUp)+len(repoUp) == 0 { } else if len(aurUp)+len(repoUp) == 0 {
fmt.Println("\nthere is nothing to do") fmt.Println("\nThere is nothing to do")
return err return err
} }
@ -302,18 +302,26 @@ func upgradePkgs(flags []string) error {
result := strings.Fields(string(numberBuf)) result := strings.Fields(string(numberBuf))
for _, numS := range result { for _, numS := range result {
var numbers []int
num, err := strconv.Atoi(numS) num, err := strconv.Atoi(numS)
if err != nil { if err != nil {
continue numbers, err = BuildRange(numS)
} if err != nil {
if num > len(aurUp)+len(repoUp)-1 || num < 0 { continue
continue }
} else if num < len(aurUp) {
num = len(aurUp) - num - 1
aurNums = append(aurNums, num)
} else { } else {
num = len(aurUp) + len(repoUp) - num - 1 numbers = []int{num}
repoNums = append(repoNums, 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)
}
} }
} }
} }