Skip to content

Commit 1621184

Browse files
committed
addressing review comments
1 parent 62d6c82 commit 1621184

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

cmd/switch.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ func runSwitch(cfg *config.Config) error {
5050
options[i] = fmt.Sprintf("%d. %s", branchIdx+1, s.Branches[branchIdx].Branch)
5151
}
5252

53-
p := prompter.New(cfg.In, cfg.Out, cfg.Err)
54-
selectFn := func(prompt, def string, opts []string) (int, error) {
55-
return p.Select(prompt, def, opts)
56-
}
53+
var selectFn func(prompt, def string, opts []string) (int, error)
5754
if cfg.SelectFn != nil {
5855
selectFn = cfg.SelectFn
56+
} else {
57+
p := prompter.New(cfg.In, cfg.Out, cfg.Err)
58+
selectFn = func(prompt, def string, opts []string) (int, error) {
59+
return p.Select(prompt, def, opts)
60+
}
5961
}
6062

6163
selected, err := selectFn("Select a branch in the stack to switch to:", "", options)
@@ -65,6 +67,12 @@ func runSwitch(cfg *config.Config) error {
6567
printInterrupt(cfg)
6668
return errInterrupt
6769
}
70+
cfg.Errorf("failed to select branch: %v", err)
71+
return ErrSilent
72+
}
73+
74+
if selected < 0 || selected >= n {
75+
cfg.Errorf("invalid selection")
6876
return ErrSilent
6977
}
7078

0 commit comments

Comments
 (0)