github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/internal/prompter/test.go (about) 1 package prompter 2 3 import "fmt" 4 5 // Test helpers 6 7 func IndexFor(options []string, answer string) (int, error) { 8 for ix, a := range options { 9 if a == answer { 10 return ix, nil 11 } 12 } 13 return -1, NoSuchAnswerErr(answer) 14 } 15 16 func NoSuchAnswerErr(answer string) error { 17 return fmt.Errorf("no such answer '%s'", answer) 18 } 19 20 func NoSuchPromptErr(prompt string) error { 21 return fmt.Errorf("no such prompt '%s'", prompt) 22 }