-
Notifications
You must be signed in to change notification settings - Fork 7
/
prompter.go
47 lines (38 loc) · 970 Bytes
/
prompter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//go:generate mockgen -source=./prompter.go -destination=mockPrompter.go -package=prompter
package prompter
import (
"errors"
"fmt"
"sync"
"github.com/denizgursoy/gotouch/internal/manager"
)
var (
once = sync.Once{}
prompter Prompter
EmptyList = errors.New("options can not be empty")
)
type (
Prompter interface {
AskForString(direction string, validator Validator) (string, error)
AskForSelectionFromList(direction string, list []fmt.Stringer) (any, error)
AskForMultipleSelectionFromList(direction string, list []fmt.Stringer) ([]any, error)
AskForYesOrNo(direction string) (bool, error)
AskForMultilineString(direction, defaultValue, pattern string) (string, error)
}
ListOption struct {
DisplayText string
ReturnVal any
}
Validator func(any) error
srv struct {
Manager manager.Manager
}
)
func GetInstance() Prompter {
once.Do(func() {
prompter = &srv{
Manager: manager.GetInstance(),
}
})
return prompter
}