-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain.go
43 lines (34 loc) · 825 Bytes
/
main.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
// Package main demonstrates how promptkit/textinput can be used to ask for
// passphrases.
package main
import (
"fmt"
"os"
"github.com/erikgeiser/promptkit/textinput"
)
const minCharacters = 10
func main() {
input := textinput.New("Choose a passphrase:")
input.Placeholder = "make it strong!"
input.Validate = func(s string) error {
if s == "hunter2" {
return fmt.Errorf("not that one")
}
if len(s) < minCharacters {
return fmt.Errorf("at least %d more characters", minCharacters-len(s))
}
return nil
}
input.Hidden = true
input.Template += `
{{- if .ValidationError -}}
{{- print " " (Foreground "1" .ValidationError.Error) -}}
{{- end -}}`
name, err := input.RunPrompt()
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
// do something with the result
_ = name
}