aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bridge_configure.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-10-03 21:05:19 +0200
committerMichael Muré <batolettre@gmail.com>2018-10-03 21:05:19 +0200
commitf37155d00ff58b1f9f6dfe54e407b95d4b067491 (patch)
tree54b48b2234dec8cb1899e474513cfb9644f81eab /commands/bridge_configure.go
parent61f16ce15a8d5865675294550f655bada3a5ea53 (diff)
downloadgit-bug-f37155d00ff58b1f9f6dfe54e407b95d4b067491.tar.gz
commands: better multi choice prompt to select the target for "bridge configure"
Diffstat (limited to 'commands/bridge_configure.go')
-rw-r--r--commands/bridge_configure.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go
index f6aa6bfd..4329b54c 100644
--- a/commands/bridge_configure.go
+++ b/commands/bridge_configure.go
@@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"os"
+ "strconv"
"strings"
"github.com/MichaelMure/git-bug/bridge"
@@ -45,7 +46,10 @@ func promptTarget() (string, error) {
targets := bridge.Targets()
for {
- fmt.Printf("target (%s): ", strings.Join(targets, ","))
+ for i, target := range targets {
+ fmt.Printf("[%d]: %s\n", i+1, target)
+ }
+ fmt.Printf("target: ")
line, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
@@ -54,13 +58,13 @@ func promptTarget() (string, error) {
line = strings.TrimRight(line, "\n")
- for _, t := range targets {
- if t == line {
- return t, nil
- }
+ index, err := strconv.Atoi(line)
+ if err != nil || index <= 0 || index > len(targets) {
+ fmt.Println("invalid input")
+ continue
}
- fmt.Println("invalid target")
+ return targets[index-1], nil
}
}