Skip to content

Commit 96772b5

Browse files
author
Anand
committed
ref issue #8 - option to generate password -g
1 parent 35cc37c commit 96772b5

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

main.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ package main
44

55
import (
66
"fmt"
7+
"strconv"
78
getopt "github.com/pborman/getopt/v2"
89
"os"
910
)
1011

1112
const VERSION = 0.2
1213
const APP = "varuh"
13-
const AUTHOR_EMAIL = "Anand B Pillai <[email protected]>"
14+
const AUTHOR_EMAIL = "Anand B Pillai <[email protected]>"
1415

1516
type actionFunc func(string) error
1617
type actionFunc2 func(string) (error, string)
@@ -32,6 +33,30 @@ func printVersionInfo() error {
3233
return nil
3334
}
3435

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+
3560
// Perform an action by using the command line options map
3661
func performAction(optMap map[string]interface{}, optionMap map[string]interface{}) {
3762

@@ -59,6 +84,7 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface
5984

6085
stringActions2Map := map[string]actionFunc2{
6186
"decrypt": decryptDatabase,
87+
"genpass": generatePassword,
6288
}
6389

6490
flagsActionsMap := map[string]voidFunc{
@@ -70,7 +96,6 @@ func performAction(optMap map[string]interface{}, optionMap map[string]interface
7096
for key, mappedFunc := range flagsActionsMap {
7197
if *optMap[key].(*bool) {
7298
mappedFunc()
73-
break
7499
}
75100
}
76101

0 commit comments

Comments
 (0)