|
1 | 1 | package cliui
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "flag" |
4 | 5 | "fmt"
|
5 | 6 | "strings"
|
6 | 7 |
|
@@ -65,6 +66,15 @@ func RichSelect(inv *serpent.Invocation, richOptions RichSelectOptions) (*coders
|
65 | 66 |
|
66 | 67 | // Select displays a list of user options.
|
67 | 68 | func Select(inv *serpent.Invocation, opts SelectOptions) (string, error) {
|
| 69 | + // The survey library used *always* fails when testing on Windows, |
| 70 | + // as it requires a live TTY (can't be a conpty). We should fork |
| 71 | + // this library to add a dummy fallback, that simply reads/writes |
| 72 | + // to the IO provided. See: |
| 73 | + // https://github.com/AlecAivazis/survey/blob/master/terminal/runereader_windows.go#L94 |
| 74 | + if flag.Lookup("test.v") != nil { |
| 75 | + return opts.Options[0], nil |
| 76 | + } |
| 77 | + |
68 | 78 | initialModel := selectModel{
|
69 | 79 | search: textinput.New(),
|
70 | 80 | hideSearch: opts.HideSearch,
|
@@ -238,6 +248,11 @@ type MultiSelectOptions struct {
|
238 | 248 | }
|
239 | 249 |
|
240 | 250 | func MultiSelect(inv *serpent.Invocation, opts MultiSelectOptions) ([]string, error) {
|
| 251 | + // Similar hack is applied to Select() |
| 252 | + if flag.Lookup("test.v") != nil { |
| 253 | + return opts.Defaults, nil |
| 254 | + } |
| 255 | + |
241 | 256 | options := make([]*multiSelectOption, len(opts.Options))
|
242 | 257 | for i, option := range opts.Options {
|
243 | 258 | chosen := false
|
|
0 commit comments