commit 26c5fac0f683defda151b97f2a613d00e645cd9f
parent b2f177d92a5339910c1e329dfdd6924925896e8d
Author: Sean Enck <sean@ttypty.com>
Date: Sun, 1 Aug 2021 12:50:06 -0400
add find
Diffstat:
4 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/cmd/bash/completions.bash b/cmd/bash/completions.bash
@@ -4,7 +4,7 @@ _lb() {
local cur opts
cur=${COMP_WORDS[COMP_CWORD]}
if [ $COMP_CWORD -eq 1 ]; then
- opts="version ls clip show -c insert rm rekey totp list pwgen stats"
+ opts="version ls clip show -c insert rm rekey totp list pwgen stats find"
COMPREPLY=( $(compgen -W "$opts" -- $cur) )
else
if [ $COMP_CWORD -eq 2 ]; then
diff --git a/cmd/lb/main.go b/cmd/lb/main.go
@@ -81,12 +81,25 @@ func main() {
command := args[1]
store := internal.GetStore()
switch command {
- case "ls", "list":
+ case "ls", "list", "find":
+ isFind := command == "find"
+ searchTerm := ""
+ if isFind {
+ if len(args) < 3 {
+ internal.Die("find requires an argument to search for", internal.NewLockboxError("search term required"))
+ }
+ searchTerm = args[2]
+ }
files, err := internal.Find(store, true)
if err != nil {
internal.Die("unable to list files", err)
}
for _, f := range files {
+ if isFind {
+ if !strings.Contains(f, searchTerm) {
+ continue
+ }
+ }
fmt.Println(f)
}
case "version":
diff --git a/tests/expected.log b/tests/expected.log
@@ -11,6 +11,8 @@ rekeying: bin/lb/keys2/three.lb
remove entry? (y/N)
keys/one2
keys2/three
+keys/one2
+keys2/three
test2
test3
test4
diff --git a/tests/run.sh b/tests/run.sh
@@ -29,6 +29,7 @@ _run() {
yes | $BIN/lb rm keys/one
echo
$BIN/lb list
+ $BIN/lb find e
$BIN/lb show keys/one2
$BIN/lb show keys2/three
echo "5ae472abqdekjqykoyxk7hvc2leklq5n" | $BIN/lb insert totp/test