@@ -4,13 +4,14 @@ package main
4
4
5
5
import (
6
6
"fmt"
7
+ "strconv"
7
8
getopt "github.com/pborman/getopt/v2"
8
9
"os"
9
10
)
10
11
11
12
const VERSION = 0.2
12
13
const APP = "varuh"
13
- const AUTHOR_EMAIL = "Anand B Pillai <[email protected] >"
14
+ const AUTHOR_EMAIL = "Anand B Pillai <[email protected] >"
14
15
15
16
type actionFunc func (string ) error
16
17
type actionFunc2 func (string ) (error , string )
@@ -32,6 +33,30 @@ func printVersionInfo() error {
32
33
return nil
33
34
}
34
35
36
+ // Command-line wrapper to generateRandomPassword
37
+ func generatePassword (length string ) (error , string ) {
38
+ var iLength int
39
+ var err error
40
+ var passwd string
41
+
42
+ iLength , _ = strconv .Atoi (length )
43
+ err , passwd = generateRandomPassword (iLength )
44
+
45
+ if err != nil {
46
+ fmt .Printf ("Error generating password - \" %s\" \n " , err .Error ())
47
+ return err , ""
48
+ }
49
+
50
+ fmt .Println (passwd )
51
+
52
+ if settingsRider .CopyPassword {
53
+ copyPasswordToClipboard (passwd )
54
+ fmt .Println ("Password copied to clipboard" )
55
+ }
56
+
57
+ return nil , passwd
58
+ }
59
+
35
60
// Perform an action by using the command line options map
36
61
func performAction (optMap map [string ]interface {}, optionMap map [string ]interface {}) {
37
62
@@ -59,6 +84,7 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface
59
84
60
85
stringActions2Map := map [string ]actionFunc2 {
61
86
"decrypt" : decryptDatabase ,
87
+ "genpass" : generatePassword ,
62
88
}
63
89
64
90
flagsActionsMap := map [string ]voidFunc {
@@ -70,7 +96,6 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface
70
96
for key , mappedFunc := range flagsActionsMap {
71
97
if * optMap [key ].(* bool ) {
72
98
mappedFunc ()
73
- break
74
99
}
75
100
}
76
101
0 commit comments