-
Notifications
You must be signed in to change notification settings - Fork 1
/
inputHandlers.go
161 lines (129 loc) · 3.32 KB
/
inputHandlers.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
import (
"flag"
"fmt"
)
func argsHandler() (
interactive *bool,
erase *bool,
randomPasswords *bool,
wordChains *bool,
memorable2 *bool,
help *bool,
passPhrases *bool,
memorable *bool,
randomHex *bool,
examples *bool,
grammatical *bool,
grammaticalAI *bool,
grammaticalAIWithNumbers *bool,
mnemonic *bool,
memorable3 *bool,
memorable4 *bool,
) {
// FIXME: Only -h works, not -help or --help
help = flag.Bool(
"help",
false,
"./passwordgen -h",
)
if *help {
flag.Usage()
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
}
// Interactive mode is the default
interactive = flag.Bool(
"interactive",
true,
"./passwordgen --interactive[=false]")
erase = flag.Bool(
"erase",
true,
"./passwordgen --erase[=false]")
randomPasswords = flag.Bool(
"random",
true,
"./passwordgen --random")
wordChains = flag.Bool(
"word-chains",
false,
"./passwordgen --word-chains")
passPhrases = flag.Bool(
"passphrases",
false,
"./passwordgen --passphrases")
memorable = flag.Bool(
"memorable",
false,
"./passwordgen --memorable")
memorable2 = flag.Bool(
"memorable-2",
false,
"./passwordgen --memorable-2")
memorable3 = flag.Bool(
"memorable-3",
false,
"./passwordgen --memorable-3")
memorable4 = flag.Bool(
"memorable-4",
false,
"./passwordgen --memorable-4")
randomHex = flag.Bool(
"hex",
false,
"./passwordgen --hex")
examples = flag.Bool(
"examples",
false,
"./passwordgen --examples")
grammatical = flag.Bool(
"grammatical",
false,
"./passwordgen --grammatical")
grammaticalAI = flag.Bool(
"grammatical-ai",
false,
"./passwordgen --grammatical-ai (Requires an openai.com GPT-4 API key)")
grammaticalAIWithNumbers = flag.Bool(
"grammatical-ai-with-numbers",
false,
"./passwordgen --grammatical-ai-with-numbers (Requires an openai.com GPT-4 API key)")
mnemonic = flag.Bool(
"mnemonic",
false,
"./passwordgen --mnemonic (Requires an openai.com GPT-4 API key)")
flag.Parse()
return interactive, erase, randomPasswords, wordChains, memorable2, nil, passPhrases, memorable, randomHex, examples, grammatical, grammaticalAI, grammaticalAIWithNumbers, mnemonic, memorable3, memorable4
}
func ifInteractive(interactive *bool, rows int) bool {
// TODO: handle `--interactive=false` arg by returning one password and exiting
if *interactive {
// Declare a variable to store the user's choice of which password they select
var passwordNumber int
// Prompt the user to choose a password from the list
fmt.Print("Enter an integer: ")
for {
// Accept user input and save it to passwordNumber
// We don't need the number of args, which is the first returned value,
// so just put that in '_'
_, err := fmt.Scan(&passwordNumber)
// Check if input is an integer. If not, re-prompt the user
if err != nil {
fmt.Printf("Error: Expected input to be an integer: %s", err)
fmt.Printf("\nEnter an integer: ")
continue
}
// Check if selected password number is in range
if passwordNumber < 0 || passwordNumber >= (rows-1) {
fmt.Printf("Error: Your selection is out of range")
fmt.Printf("\nEnter an integer: ")
continue
}
break
}
// Set the global var to the entered number
selectedPasswordNumber = passwordNumber
return true
}
return false
}