Skip to content

Commit bd05925

Browse files
author
Anand
committed
ref issue #9 - Updated version number
1 parent f1ee30c commit bd05925

File tree

1 file changed

+48
-45
lines changed

1 file changed

+48
-45
lines changed

main.go

+48-45
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ package main
44

55
import (
66
"fmt"
7-
"strconv"
8-
// getopt "github.com/pborman/getopt/v2"
9-
"github.com/akamensky/argparse"
7+
"github.com/pythonhacker/argparse"
108
"os"
9+
"strconv"
1110
)
1211

13-
const VERSION = 0.2
12+
const VERSION = 0.3
1413
const APP = "varuh"
15-
const AUTHOR_EMAIL = "Anand B Pillai <[email protected]>"
14+
15+
const AUTHOR_INFO = `
16+
AUTHORS
17+
Copyright (C) 2021 Anand B Pillai <[email protected]>
18+
`
1619

1720
type actionFunc func(string) error
1821
type actionFunc2 func(string) (error, string)
1922
type voidFunc func() error
2023

2124
// Structure to keep the options data
2225
type CmdOption struct {
23-
Short string
24-
Long string
25-
Help string
26+
Short string
27+
Long string
28+
Help string
29+
Path string
2630
Default string
2731
}
2832

@@ -43,13 +47,13 @@ func printVersionInfo() error {
4347
}
4448

4549
// Command-line wrapper to generateRandomPassword
46-
func generatePassword(length string) (error, string) {
50+
func genPass(length string) (error, string) {
4751
var iLength int
4852
var err error
4953
var passwd string
50-
54+
5155
iLength, _ = strconv.Atoi(length)
52-
err, passwd = generateRandomPassword(iLength)
56+
err, passwd = generatePassword(iLength)
5357

5458
if err != nil {
5559
fmt.Printf("Error generating password - \"%s\"\n", err.Error())
@@ -62,7 +66,7 @@ func generatePassword(length string) (error, string) {
6266
copyPasswordToClipboard(passwd)
6367
fmt.Println("Password copied to clipboard")
6468
}
65-
69+
6670
return nil, passwd
6771
}
6872

@@ -93,7 +97,7 @@ func performAction(optMap map[string]interface{}) {
9397

9498
stringActions2Map := map[string]actionFunc2{
9599
"decrypt": decryptDatabase,
96-
"genpass": generatePassword,
100+
"genpass": genPass,
97101
}
98102

99103
flagsActionsMap := map[string]voidFunc{
@@ -108,7 +112,6 @@ func performAction(optMap map[string]interface{}) {
108112
}
109113
}
110114

111-
112115
// One of bool or string actions
113116
for key, mappedFunc := range boolActionsMap {
114117
if *optMap[key].(*bool) {
@@ -151,38 +154,38 @@ func initializeCmdLine(parser *argparse.Parser) map[string]interface{} {
151154

152155
optMap = make(map[string]interface{})
153156

157+
stringOptions := []CmdOption{
158+
{"I", "init", "Initialize a new database", "<path>", ""},
159+
{"d", "decrypt", "Decrypt password database", "<path>", ""},
160+
{"C", "clone", "Clone an entry with <id>", "<id>", ""},
161+
{"R", "remove", "Remove an entry with <id>", "<id>", ""},
162+
{"U", "use-db", "Set <path> as active database", "<path>", ""},
163+
{"f", "find", "Search entries with <term>", "<term>", ""},
164+
{"E", "edit", "Edit entry by <id>", "<id>", ""},
165+
{"l", "list-entry", "List entry by <id>", "<id>", ""},
166+
{"x", "export", "Export all entries to <filename>", "<filename>", ""},
167+
{"g", "genpass", "Generate password of given <length>", "<length>", ""},
168+
}
169+
170+
for _, opt := range stringOptions {
171+
optMap[opt.Long] = parser.String(opt.Short, opt.Long, &argparse.Options{Help: opt.Help, Path: opt.Path})
172+
}
173+
154174
boolOptions := []CmdOption{
155-
{"e", "encrypt", "Encrypt the current database", ""},
156-
{"A", "add", "Add a new entry", ""},
157-
{"p", "path", "Show current database path", ""},
158-
{"a", "list-all", "List all entries in current database", ""},
159-
{"s", "show", "Show passwords when listing entries", ""},
160-
{"c", "copy", "Copy password to clipboard", ""},
161-
{"v", "version", "Show version information and exit", ""},
162-
{"h", "help", "Print this help message and exit", ""},
175+
{"e", "encrypt", "Encrypt the current database", "", ""},
176+
{"A", "add", "Add a new entry", "", ""},
177+
{"p", "path", "Show current database path", "", ""},
178+
{"a", "list-all", "List all entries in current database", "", ""},
179+
{"s", "show", "Show passwords when listing entries", "", ""},
180+
{"c", "copy", "Copy password to clipboard", "", ""},
181+
{"v", "version", "Show version information and exit", "", ""},
182+
{"h", "help", "Print this help message and exit", "", ""},
163183
}
164184

165185
for _, opt := range boolOptions {
166186
optMap[opt.Long] = parser.Flag(string(opt.Short), opt.Long, &argparse.Options{Help: opt.Help})
167-
}
168-
169-
stringOptions := []CmdOption{
170-
{"I", "init", "Initialize a new database", ""},
171-
{"d", "decrypt", "Decrypt password database", ""},
172-
{"C", "clone", "Clone an entry", ""},
173-
{"R", "remove", "Remove an entry", ""},
174-
{"U", "use-db", "Set as active database", ""},
175-
{"f", "find", "Search entries", ""},
176-
{"E", "edit", "Edit entry by id", ""},
177-
{"l", "list-entry", "List entry by id", ""},
178-
{"x", "export", "Export all entries to <filename>", ""},
179-
{"g", "genpass", "Generate password of given length", "12"},
180187
}
181188

182-
for _, opt := range stringOptions {
183-
optMap[opt.Long] = parser.String(opt.Short, opt.Long, &argparse.Options{Help: opt.Help, Default: opt.Default})
184-
}
185-
186189
return optMap
187190
}
188191

@@ -192,19 +195,19 @@ func main() {
192195
os.Args = append(os.Args, "-h")
193196
}
194197

195-
parser := argparse.NewParser("varuh", "Password manager for the command line for Unix like operating systems")
196-
197-
// optMap, optionMap := initializeCommandLine(parser)
198+
parser := argparse.NewParser("varuh",
199+
"Password manager for the command line for Unix like operating systems",
200+
AUTHOR_INFO,
201+
)
198202

199-
// versionFlag := parser.Flag("v", "version", &argparse.Options{Help: "Show version information and exit"})
200203
optMap := initializeCmdLine(parser)
201-
204+
202205
err := parser.Parse(os.Args)
203206

204207
if err != nil {
205208
fmt.Println(parser.Usage(err))
206209
}
207-
210+
208211
getOrCreateLocalConfig(APP)
209212

210213
performAction(optMap)

0 commit comments

Comments
 (0)