lockbox

password manager
Log | Files | Refs | README | LICENSE

commit a5ecaca28ee7549bd99e1bd2ef081c1fc8a765be
parent 70738f06f9872cbd68621507d871c52b66c91ca1
Author: Sean Enck <sean@ttypty.com>
Date:   Thu, 30 Mar 2023 19:39:13 -0400

rename hash -> conv

Diffstat:
MREADME.md | 2+-
Mcmd/main.go | 4++--
Ainternal/app/conv.go | 32++++++++++++++++++++++++++++++++
Ainternal/app/conv_test.go | 23+++++++++++++++++++++++
Dinternal/app/hash.go | 32--------------------------------
Dinternal/app/hash_test.go | 23-----------------------
Minternal/cli/core.go | 4++--
Mtests/run.sh | 2+-
8 files changed, 61 insertions(+), 61 deletions(-)

diff --git a/README.md b/README.md @@ -86,7 +86,7 @@ lb totp clip token To manage the `.kdbx` file in a git repository and see _actual_ text diffs add this to a `.gitconfig` ``` [diff "lb"] - textconv = lb hash + textconv = lb conv ``` Setup the `.gitattributes` for the repository to include diff --git a/cmd/main.go b/cmd/main.go @@ -88,8 +88,8 @@ func run() error { return app.Stats(p) case cli.ShowCommand, cli.ClipCommand: return app.ShowClip(p, command == cli.ShowCommand) - case cli.HashCommand: - return app.Hash(p) + case cli.ConvCommand: + return app.Conv(p) case cli.TOTPCommand: args, err := totp.NewArguments(sub, inputs.TOTPToken()) if err != nil { diff --git a/internal/app/conv.go b/internal/app/conv.go @@ -0,0 +1,32 @@ +package app + +import ( + "errors" + "fmt" + "strings" + + "github.com/enckse/lockbox/internal/backend" +) + +// Conv will hash 1-N files +func Conv(cmd CommandOptions) error { + args := cmd.Args() + if len(args) == 0 { + return errors.New("hash requires a file") + } + w := cmd.Writer() + for _, a := range args { + t, err := backend.Load(a) + if err != nil { + return err + } + e, err := t.QueryCallback(backend.QueryOptions{Mode: backend.ListMode, Values: backend.HashedValue}) + if err != nil { + return err + } + for _, item := range e { + fmt.Fprintf(w, "%s:\n %s\n\n", item.Path, strings.ReplaceAll(item.Value, "\n", "\n ")) + } + } + return nil +} diff --git a/internal/app/conv_test.go b/internal/app/conv_test.go @@ -0,0 +1,23 @@ +package app_test + +import ( + "bytes" + "testing" + + "github.com/enckse/lockbox/internal/app" +) + +func TestConv(t *testing.T) { + c := newMockCommand(t) + if err := app.Conv(c); err.Error() != "hash requires a file" { + t.Errorf("invalid error: %v", err) + } + c.buf = bytes.Buffer{} + c.args = []string{"test.kdbx"} + if err := app.Conv(c); err != nil { + t.Errorf("invalid error: %v", err) + } + if c.buf.String() == "" { + t.Error("nothing hashed") + } +} diff --git a/internal/app/hash.go b/internal/app/hash.go @@ -1,32 +0,0 @@ -package app - -import ( - "errors" - "fmt" - "strings" - - "github.com/enckse/lockbox/internal/backend" -) - -// Hash will hash 1-N files -func Hash(cmd CommandOptions) error { - args := cmd.Args() - if len(args) == 0 { - return errors.New("hash requires a file") - } - w := cmd.Writer() - for _, a := range args { - t, err := backend.Load(a) - if err != nil { - return err - } - e, err := t.QueryCallback(backend.QueryOptions{Mode: backend.ListMode, Values: backend.HashedValue}) - if err != nil { - return err - } - for _, item := range e { - fmt.Fprintf(w, "%s:\n %s\n\n", item.Path, strings.ReplaceAll(item.Value, "\n", "\n ")) - } - } - return nil -} diff --git a/internal/app/hash_test.go b/internal/app/hash_test.go @@ -1,23 +0,0 @@ -package app_test - -import ( - "bytes" - "testing" - - "github.com/enckse/lockbox/internal/app" -) - -func TestHash(t *testing.T) { - c := newMockCommand(t) - if err := app.Hash(c); err.Error() != "hash requires a file" { - t.Errorf("invalid error: %v", err) - } - c.buf = bytes.Buffer{} - c.args = []string{"test.kdbx"} - if err := app.Hash(c); err != nil { - t.Errorf("invalid error: %v", err) - } - if c.buf.String() == "" { - t.Error("nothing hashed") - } -} diff --git a/internal/cli/core.go b/internal/cli/core.go @@ -19,8 +19,8 @@ const ( StatsCommand = "stats" // TOTPCommand is the parent of totp and by defaults generates a rotating token TOTPCommand = "totp" - // HashCommand handles hashing the data store - HashCommand = "hash" + // ConvCommand handles text conversion of the data store + ConvCommand = "conv" // ClearCommand is a callback to manage clipboard clearing ClearCommand = "clear" // ClipCommand will copy values to the clipboard diff --git a/tests/run.sh b/tests/run.sh @@ -37,7 +37,7 @@ _execute() { ${LB_BINARY} totp show test/k ${LB_BINARY} totp once test/k ${LB_BINARY} totp minimal test/k - ${LB_BINARY} hash "$LOCKBOX_STORE" + ${LB_BINARY} conv "$LOCKBOX_STORE" echo y |${LB_BINARY} rm keys2/k/three echo echo y |${LB_BINARY} rm test/k/totp