6
6
"fmt"
7
7
"github.com/pythonhacker/argparse"
8
8
"os"
9
- "strconv"
10
9
)
11
10
12
11
const VERSION = 0.3
@@ -20,6 +19,7 @@ AUTHORS
20
19
type actionFunc func (string ) error
21
20
type actionFunc2 func (string ) (error , string )
22
21
type voidFunc func () error
22
+ type voidFunc2 func () (error , string )
23
23
24
24
// Structure to keep the options data
25
25
type CmdOption struct {
@@ -47,13 +47,11 @@ func printVersionInfo() error {
47
47
}
48
48
49
49
// Command-line wrapper to generateRandomPassword
50
- func genPass (length string ) (error , string ) {
51
- var iLength int
50
+ func genPass () (error , string ) {
52
51
var err error
53
52
var passwd string
54
53
55
- iLength , _ = strconv .Atoi (length )
56
- err , passwd = generatePassword (iLength )
54
+ err , passwd = generateStrongPassword ()
57
55
58
56
if err != nil {
59
57
fmt .Printf ("Error generating password - \" %s\" \n " , err .Error ())
@@ -97,6 +95,9 @@ func performAction(optMap map[string]interface{}) {
97
95
98
96
stringActions2Map := map [string ]actionFunc2 {
99
97
"decrypt" : decryptDatabase ,
98
+ }
99
+
100
+ flagsActions2Map := map [string ]voidFunc2 {
100
101
"genpass" : genPass ,
101
102
}
102
103
@@ -112,6 +113,15 @@ func performAction(optMap map[string]interface{}) {
112
113
}
113
114
}
114
115
116
+ // Flag 2 actions
117
+ for key , mappedFunc := range flagsActions2Map {
118
+ if * optMap [key ].(* bool ) {
119
+ mappedFunc ()
120
+ flag = true
121
+ break
122
+ }
123
+ }
124
+
115
125
// One of bool or string actions
116
126
for key , mappedFunc := range boolActionsMap {
117
127
if * optMap [key ].(* bool ) {
@@ -164,7 +174,6 @@ func initializeCmdLine(parser *argparse.Parser) map[string]interface{} {
164
174
{"E" , "edit" , "Edit entry by <id>" , "<id>" , "" },
165
175
{"l" , "list-entry" , "List entry by <id>" , "<id>" , "" },
166
176
{"x" , "export" , "Export all entries to <filename>" , "<filename>" , "" },
167
- {"g" , "genpass" , "Generate password of given <length>" , "<length>" , "" },
168
177
}
169
178
170
179
for _ , opt := range stringOptions {
@@ -176,6 +185,7 @@ func initializeCmdLine(parser *argparse.Parser) map[string]interface{} {
176
185
{"A" , "add" , "Add a new entry" , "" , "" },
177
186
{"p" , "path" , "Show current database path" , "" , "" },
178
187
{"a" , "list-all" , "List all entries in current database" , "" , "" },
188
+ {"g" , "genpass" , "Generate a strong password of length from 8 - 12" , "" , "" },
179
189
{"s" , "show" , "Show passwords when listing entries" , "" , "" },
180
190
{"c" , "copy" , "Copy password to clipboard" , "" , "" },
181
191
{"v" , "version" , "Show version information and exit" , "" , "" },
0 commit comments