Skip to content

Commit 94c70da

Browse files
authored
Merge pull request #8 from xenit-eu/fix-org-apikey
Fix bug creating an API key for the wrong org
2 parents a45b6a9 + b06a022 commit 94c70da

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

main.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"os/exec"
1010
"runtime"
11+
"sort"
1112
"strconv"
1213
"syscall"
1314
"time"
@@ -57,25 +58,28 @@ func main() {
5758
}
5859

5960
if *chosenOrgName == "" {
60-
fmt.Println("Available organizations: ")
61-
i := 1
61+
orgNames := make([]string, 0, len(orgs))
6262
for name := range orgs {
63-
fmt.Println(i, ".", name)
64-
i++
63+
orgNames = append(orgNames, name)
64+
}
65+
66+
sort.Strings(orgNames) // Optional: sort for consistent ordering
67+
68+
fmt.Println("Available organizations: ")
69+
for i, name := range orgNames {
70+
fmt.Println(i+1, ".", name)
6571
}
6672

6773
fmt.Print("Choose an organization by entering the corresponding number: ")
6874
scanner.Scan()
6975
chosenNumber, _ := strconv.Atoi(scanner.Text())
7076

71-
i = 1
72-
for name := range orgs {
73-
if i == chosenNumber {
74-
*chosenOrgName = name
75-
break
76-
}
77-
i++
77+
if chosenNumber < 1 || chosenNumber > len(orgNames) {
78+
fmt.Println("Invalid selection.")
79+
return
7880
}
81+
82+
*chosenOrgName = orgNames[chosenNumber-1]
7983
}
8084

8185
if *chosenDuration == 0 {

0 commit comments

Comments
 (0)