Skip to content

Commit 39da91f

Browse files
committed
feat: add ReadTextSlice, ReadIntSlice, ReadURLSlice
Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
1 parent ec46421 commit 39da91f

File tree

4 files changed

+524
-201
lines changed

4 files changed

+524
-201
lines changed

prompts/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func EditFileValidatedByLine(prompt, content, separator string, lineValidate fun
102102
lines := strings.Split(string(partsBytes), "\n")
103103

104104
finalLines, err := stripCommentsAndValidateLines(lines, lineValidate)
105-
if err != nil && errors.Is(err, ValidationError) {
105+
if err != nil && errors.Is(err, ErrValidationFailed) {
106106
// for integration tests, return the error
107107
if os.Getenv("IS_TEST") == "true" {
108108
return "", err

prompts/mocks/prompt_mocks.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
)
99

1010
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
1416
}
1517

1618
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
3537
return m.run()
3638
}
3739

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+
3847
func (m *MockTUI) GetSelection(prompt string, options []string) (string, error) {
3948
val, err := m.run()
4049
if err != nil {
@@ -59,7 +68,7 @@ func (m *MockTUI) GetMultiSelection(prompt string, options []string, minSelectio
5968
}
6069

6170
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:]
6372
if m.validate != nil {
6473
validateErr := m.validate(val)
6574
if validateErr != nil {
@@ -72,3 +81,18 @@ func (m *MockTUI) run() (val string, err error) {
7281
}
7382
return val, err
7483
}
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

Comments
 (0)