Skip to content

Commit c3bbb25

Browse files
author
Anand
committed
ref issue #10 - Search multiple terms using AND operator
1 parent 03e5ef0 commit c3bbb25

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

main.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"github.com/pythonhacker/argparse"
88
"os"
9+
"strings"
910
)
1011

1112
const VERSION = 0.3
@@ -86,13 +87,16 @@ func performAction(optMap map[string]interface{}) {
8687
"edit": WrapperMaxKryptStringFunc(editCurrentEntry),
8788
"init": initNewDatabase,
8889
"list-entry": WrapperMaxKryptStringFunc(listCurrentEntry),
89-
"find": WrapperMaxKryptStringFunc(findCurrentEntry),
9090
"remove": WrapperMaxKryptStringFunc(removeCurrentEntry),
9191
"clone": WrapperMaxKryptStringFunc(copyCurrentEntry),
9292
"use-db": setActiveDatabasePath,
9393
"export": exportToFile,
9494
}
9595

96+
stringListActionsMap := map[string]actionFunc{
97+
"find": WrapperMaxKryptStringFunc(findCurrentEntry),
98+
}
99+
96100
stringActions2Map := map[string]actionFunc2{
97101
"decrypt": decryptDatabase,
98102
}
@@ -146,6 +150,18 @@ func performAction(optMap map[string]interface{}) {
146150
}
147151
}
148152

153+
for key, mappedFunc := range stringListActionsMap {
154+
if len(*optMap[key].(*[]string)) > 0 {
155+
156+
var vals = *(optMap[key].(*[]string))
157+
// Convert to single string
158+
var singleVal = strings.Join(vals, " ")
159+
mappedFunc(singleVal)
160+
flag = true
161+
break
162+
}
163+
}
164+
149165
if flag {
150166
return
151167
}
@@ -171,7 +187,6 @@ func initializeCmdLine(parser *argparse.Parser) map[string]interface{} {
171187
{"C", "clone", "Clone an entry with <id>", "<id>", ""},
172188
{"R", "remove", "Remove an entry with <id> or <id-range>", "<id>", ""},
173189
{"U", "use-db", "Set <path> as active database", "<path>", ""},
174-
{"f", "find", "Search entries with <term>", "<term>", ""},
175190
{"E", "edit", "Edit entry by <id>", "<id>", ""},
176191
{"l", "list-entry", "List entry by <id>", "<id>", ""},
177192
{"x", "export", "Export all entries to <filename>", "<filename>", ""},
@@ -181,6 +196,14 @@ func initializeCmdLine(parser *argparse.Parser) map[string]interface{} {
181196
optMap[opt.Long] = parser.String(opt.Short, opt.Long, &argparse.Options{Help: opt.Help, Path: opt.Path})
182197
}
183198

199+
stringListOptions := []CmdOption{
200+
{"f", "find", "Search entries with terms", "<t1> <t2> ...", ""},
201+
}
202+
203+
for _, opt := range stringListOptions {
204+
optMap[opt.Long] = parser.StringList(opt.Short, opt.Long, &argparse.Options{Help: opt.Help, Path: opt.Path})
205+
}
206+
184207
boolOptions := []CmdOption{
185208
{"e", "encrypt", "Encrypt the current database", "", ""},
186209
{"A", "add", "Add a new entry", "", ""},

0 commit comments

Comments
 (0)