lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 6687f43eb4ddaf1164afabe9b635794daea13d45
parent f5555afa2fce2cff522e2246008e3971fa4ba006
Author: Sean Enck <sean@ttypty.com>
Date:   Sun,  2 Oct 2022 13:44:03 -0400

these args are almost ALL totp

Diffstat:
Mcmd/main.go | 9++++-----
Dinternal/cli/args.go | 26--------------------------
Dinternal/cli/args_test.go | 53-----------------------------------------------------
Minternal/totp/core.go | 20+++++++++++++++++---
4 files changed, 21 insertions(+), 87 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go @@ -11,7 +11,6 @@ import ( "time" "github.com/enckse/lockbox/internal/backend" - "github.com/enckse/lockbox/internal/cli" "github.com/enckse/lockbox/internal/inputs" "github.com/enckse/lockbox/internal/platform" "github.com/enckse/lockbox/internal/totp" @@ -117,17 +116,17 @@ func run() *programError { return newError("unable to move object", err) } case "insert": - options := cli.Arguments{} + multi := false idx := 2 switch len(args) { case 2: return newError("insert missing required arguments", errors.New("entry required")) case 3: case 4: - options = cli.ParseArgs(args[2]) - if !options.Multi { + if args[2] != "-multi" { return newError("multi-line insert must be after 'insert'", errors.New("invalid command")) } + multi = true idx = 3 default: return newError("too many arguments", errors.New("insert can only perform one operation")) @@ -145,7 +144,7 @@ func run() *programError { } } } - password, err := inputs.GetUserInputPassword(isPipe, options.Multi) + password, err := inputs.GetUserInputPassword(isPipe, multi) if err != nil { return newError("invalid input", err) } diff --git a/internal/cli/args.go b/internal/cli/args.go @@ -1,26 +0,0 @@ -// Package cli handles simplistic CLI handler for flags. -package cli - -type ( - // Arguments options for operations. - Arguments struct { - Clip bool - Once bool - Short bool - List bool - Multi bool - Yes bool - } -) - -// ParseArgs parses CLI arguments. -func ParseArgs(arg string) Arguments { - args := Arguments{} - args.Clip = arg == "-clip" - args.Once = arg == "-once" - args.Short = arg == "-short" - args.List = arg == "-list" - args.Multi = arg == "-multi" - args.Yes = arg == "-yes" - return args -} diff --git a/internal/cli/args_test.go b/internal/cli/args_test.go @@ -1,53 +0,0 @@ -package cli_test - -import ( - "testing" - - "github.com/enckse/lockbox/internal/cli" -) - -func TestClipArg(t *testing.T) { - options := cli.ParseArgs("-clip") - if !options.Clip { - t.Error("clip should be set") - } -} - -func TestMultiArg(t *testing.T) { - options := cli.ParseArgs("-multi") - if !options.Multi { - t.Error("multi should be set") - } -} - -func TestListArg(t *testing.T) { - options := cli.ParseArgs("-list") - if !options.List { - t.Error("list should be set") - } -} - -func TestOnce(t *testing.T) { - if options := cli.ParseArgs("-once"); !options.Once { - t.Error("once should be set") - } -} - -func TestShort(t *testing.T) { - if options := cli.ParseArgs("-short"); !options.Short { - t.Error("short should be set") - } -} - -func TestYes(t *testing.T) { - if options := cli.ParseArgs("-yes"); !options.Yes { - t.Error("yes should be set") - } -} - -func TestDefaults(t *testing.T) { - args := cli.ParseArgs("this/is/a/test") - if args.Clip || args.Once || args.Short || args.List || args.Multi || args.Yes { - t.Error("defaults should all be false") - } -} diff --git a/internal/totp/core.go b/internal/totp/core.go @@ -11,7 +11,6 @@ import ( "time" "github.com/enckse/lockbox/internal/backend" - "github.com/enckse/lockbox/internal/cli" "github.com/enckse/lockbox/internal/colors" "github.com/enckse/lockbox/internal/inputs" "github.com/enckse/lockbox/internal/platform" @@ -23,6 +22,12 @@ type ( start int end int } + arguments struct { + Clip bool + Once bool + Short bool + List bool + } ) func clear() { @@ -70,7 +75,7 @@ func colorWhenRules() ([]colorWhen, error) { return rules, nil } -func display(token string, args cli.Arguments) error { +func display(token string, args arguments) error { interactive, err := inputs.IsInteractive() if err != nil { return err @@ -184,7 +189,7 @@ func Call(args []string) error { return errors.New("invalid arguments, subkey and entry required") } cmd := args[0] - options := cli.ParseArgs(cmd) + options := parseArgs(cmd) if options.List { t, err := backend.NewTransaction() if err != nil { @@ -210,3 +215,12 @@ func Call(args []string) error { } return nil } + +func parseArgs(arg string) arguments { + args := arguments{} + args.Clip = arg == "-clip" + args.Once = arg == "-once" + args.Short = arg == "-short" + args.List = arg == "-list" + return args +}