Skip to content

Commit f88ae39

Browse files
author
Wei
authored
Merge pull request #4 from cloudpilot-ai/jwcesign-dev-general
feat: support range
2 parents 5fc9ae7 + bc6f1c9 commit f88ae39

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

select_workloads.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,34 @@ import (
1212
)
1313

1414
func selectWorkloads(scanner *bufio.Scanner) ([]Workload, error) {
15-
fmt.Println("Input the workload id which should be selected, Example: 0,1,2,3")
15+
fmt.Println("Input the workload id which should be selected, example: 0,1,2,3; or a range, example 1-9")
1616
fmt.Print("Input: ")
1717

1818
if !scanner.Scan() {
1919
return nil, fmt.Errorf("input nothing")
2020
}
2121
input := scanner.Text()
22-
workloadsIDs := strings.Split(input, ",")
22+
23+
var workloadsIDs []string
24+
if strings.Contains(input, ",") {
25+
workloadsIDs = strings.Split(input, ",")
26+
}
27+
if strings.Contains(input, "-") {
28+
ids := strings.Split(input, "-")
29+
startIDStr, endIDStr := ids[0], ids[1]
30+
31+
startID, err := strconv.Atoi(startIDStr)
32+
if err != nil {
33+
return nil, err
34+
}
35+
endID, err := strconv.Atoi(endIDStr)
36+
if err != nil {
37+
return nil, err
38+
}
39+
for i := startID; i <= endID; i++ {
40+
workloadsIDs = append(workloadsIDs, strconv.Itoa(i))
41+
}
42+
}
2343

2444
selectedWorkloads := make([]Workload, len(workloadsIDs))
2545
for i, id := range workloadsIDs {

0 commit comments

Comments
 (0)