@@ -8,9 +8,11 @@ import (
8
8
)
9
9
10
10
type MockTUI struct {
11
- ReturnVals []string
12
- Errs []error
13
- validate func (string ) error
11
+ Values []string
12
+ SliceValues [][]string
13
+ Errs []error
14
+ validate func (string ) error
15
+ validateSlice func ([]string ) error
14
16
}
15
17
16
18
func (m * MockTUI ) GetBool (prompt string , defaultVal bool ) (bool , error ) {
@@ -35,6 +37,13 @@ func (m *MockTUI) GetText(prompt, defaultVal, mask string, optional bool, valida
35
37
return m .run ()
36
38
}
37
39
40
+ func (m * MockTUI ) GetTextSlice (prompt , defaultVal string , optional bool , validate func ([]string ) error ) ([]string , error ) {
41
+ if validate != nil {
42
+ m .validateSlice = validate
43
+ }
44
+ return m .runSlice ()
45
+ }
46
+
38
47
func (m * MockTUI ) GetSelection (prompt string , options []string ) (string , error ) {
39
48
val , err := m .run ()
40
49
if err != nil {
@@ -59,7 +68,7 @@ func (m *MockTUI) GetMultiSelection(prompt string, options []string, minSelectio
59
68
}
60
69
61
70
func (m * MockTUI ) run () (val string , err error ) {
62
- val , m .ReturnVals = m .ReturnVals [0 ], m .ReturnVals [1 :]
71
+ val , m .Values = m .Values [0 ], m .Values [1 :]
63
72
if m .validate != nil {
64
73
validateErr := m .validate (val )
65
74
if validateErr != nil {
@@ -72,3 +81,18 @@ func (m *MockTUI) run() (val string, err error) {
72
81
}
73
82
return val , err
74
83
}
84
+
85
+ func (m * MockTUI ) runSlice () (val []string , err error ) {
86
+ val , m .SliceValues = m .SliceValues [0 ], m .SliceValues [1 :]
87
+ if m .validateSlice != nil {
88
+ validateErr := m .validateSlice (val )
89
+ if validateErr != nil {
90
+ m .Errs = []error {validateErr }
91
+ }
92
+ m .validateSlice = nil // reset for subsequent prompts
93
+ }
94
+ if m .Errs != nil {
95
+ err , m .Errs = m .Errs [0 ], m .Errs [1 :]
96
+ }
97
+ return val , err
98
+ }
0 commit comments