-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.go
96 lines (78 loc) · 1.77 KB
/
input.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"github.com/manifoldco/promptui"
"strconv"
"time"
)
// inputInteger, prompt that will validate integer input.
func inputInteger(name string) int {
d := promptui.Prompt{
Label: name,
Validate: validateNumber,
}
input, _ := d.Run()
result, _ := strconv.Atoi(input)
return result
}
// inputString, prompt that will validate input type string.
func inputString(name string) string {
d := promptui.Prompt{
Label: name,
Validate: validateNumber,
}
input, _ := d.Run()
return input
}
// inputDoseNumber, this will allow you to select dose number
// Currently there are 2 dose available.
func inputDoseNumber() int {
dz := promptui.Select{
Label: "Select Dose Number",
Items: []string{"1", "2"},
}
selectedDoseIndex, _, _ := dz.Run()
if selectedDoseIndex == 0 {
return 1
}
return 2
}
// inputVaccine: Input Vaccine.
func inputVaccine() string {
v := promptui.Select{
Label: "Select Vaccine",
Items: []string{"ANY", "COVAXIN", "COVISHIELD"},
}
_, vaccine, err := v.Run()
if err != nil {
panic("inputVaccine: Invalid Vaccine Name Selected")
}
return vaccine
}
// inputAge, prompt to allow select age group.
func inputAge() int {
a := promptui.Select{
Label: "Select Age",
Items: []string{"18", "45"},
}
selectedAgeIndex, _, err := a.Run()
if err != nil {
panic("inputAge: Invalid Age Selected")
}
if selectedAgeIndex == 0 {
return 18
}
return 45
}
// inputStartDate: Prompt that will take input date.
func inputStartDate() string {
date := promptui.Prompt{
Label: fmt.Sprintf("Enter Start Date DD-MM-YYYY, Today Is: %s", time.Now().Format("02-01-2006")),
Validate: validateDate,
}
startDate, err := date.Run()
if err != nil {
panic("inputStartDate: Invalid Date Selected")
}
return startDate
}