-
Notifications
You must be signed in to change notification settings - Fork 3
/
validation.go
54 lines (43 loc) · 1008 Bytes
/
validation.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
48
49
50
51
52
53
54
package key
import (
"os"
"github.com/beeper/beepycli/utils"
"github.com/charmbracelet/bubbletea"
gloss "github.com/charmbracelet/lipgloss"
)
var (
okValidation = gloss.NewStyle().
Foreground(utils.Green).
SetString("✔")
loadingValidation = gloss.NewStyle().
Foreground(utils.Yellow).
SetString("↻")
errValidation = gloss.NewStyle().
Foreground(utils.Red).
SetString("✘")
)
type fileOkMsg struct{}
type fileLoadingMsg struct{}
type fileErrMsg struct{}
func prevalidate() tea.Msg {
return fileLoadingMsg{}
}
func validateKey(path string) tea.Cmd {
return func() tea.Msg {
file, err := os.Open(path)
if err != nil {
return fileErrMsg{}
}
info, err := file.Stat()
if err != nil || info.IsDir() {
return fileErrMsg{}
}
return fileOkMsg{}
}
}
type passwordValidationMsg bool
func validatePassword(password, confirmation string) tea.Cmd {
return func() tea.Msg {
return passwordValidationMsg(len(password) > 0 && password == confirmation)
}
}