@@ -92,18 +92,25 @@ func Select(inv *serpent.Invocation, opts SelectOptions) (string, error) {
92
92
93
93
m , err := tea .NewProgram (
94
94
initialModel ,
95
+ tea .WithContext (inv .Context ()),
95
96
tea .WithInput (inv .Stdin ),
96
97
tea .WithOutput (inv .Stdout ),
97
98
).Run ()
98
99
99
- var value string
100
- if m , ok := m .(selectModel ); ok {
101
- if m .canceled {
102
- return value , Canceled
103
- }
104
- value = m .selected
100
+ if err != nil {
101
+ return "" , err
102
+ }
103
+
104
+ model , ok := m .(selectModel )
105
+ if ! ok {
106
+ return "" , xerrors .New (fmt .Sprintf ("unknown model found %T (%+v)" , m , m ))
105
107
}
106
- return value , err
108
+
109
+ if model .canceled {
110
+ return "" , Canceled
111
+ }
112
+
113
+ return model .selected , err
107
114
}
108
115
109
116
type selectModel struct {
@@ -286,19 +293,25 @@ func MultiSelect(inv *serpent.Invocation, opts MultiSelectOptions) ([]string, er
286
293
287
294
m , err := tea .NewProgram (
288
295
initialModel ,
296
+ tea .WithContext (inv .Context ()),
289
297
tea .WithInput (inv .Stdin ),
290
298
tea .WithOutput (inv .Stdout ),
291
299
).Run ()
292
300
293
- values := []string {}
294
- if m , ok := m .(multiSelectModel ); ok {
295
- if m .canceled {
296
- return values , Canceled
297
- }
301
+ if err != nil {
302
+ return nil , err
303
+ }
298
304
299
- values = m .selectedOptions ()
305
+ model , ok := m .(multiSelectModel )
306
+ if ! ok {
307
+ return nil , xerrors .New (fmt .Sprintf ("unknown model found %T (%+v)" , m , m ))
300
308
}
301
- return values , err
309
+
310
+ if model .canceled {
311
+ return nil , Canceled
312
+ }
313
+
314
+ return model .selectedOptions (), err
302
315
}
303
316
304
317
type multiSelectOption struct {
0 commit comments