From 6d2dcad0911de5ab53bc49e520bfc439be34b5e7 Mon Sep 17 00:00:00 2001 From: Samuel Henrique Oliveira da Silva Date: Sun, 14 Jan 2018 14:04:15 -0200 Subject: [PATCH] Replicates the range functionally to upgrade --- cmd.go | 9 +++++---- upgrade.go | 28 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/cmd.go b/cmd.go index 677c9b0a..26d61bb5 100644 --- a/cmd.go +++ b/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 } diff --git a/upgrade.go b/upgrade.go index bdf52edc..b9455350 100644 --- a/upgrade.go +++ b/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) + } } } }