commit bf24ed57212cbb380c735f28f73f3cbcc73e3933
parent ca667fd78ebadf33ca89ba196040c5f70b1f4363
Author: Sean Enck <sean@ttypty.com>
Date: Sat, 7 Jun 2025 19:48:39 -0400
this iota is unneeded
Diffstat:
2 files changed, 19 insertions(+), 46 deletions(-)
diff --git a/internal/app/totp.go b/internal/app/totp.go
@@ -26,12 +26,10 @@ var (
)
type (
- // Mode is the operating mode for TOTP operations
- Mode int
// TOTPArguments are the parsed TOTP call arguments
TOTPArguments struct {
Entry string
- Mode Mode
+ Mode string
}
totpWrapper struct {
code string
@@ -46,25 +44,6 @@ type (
}
)
-const (
- // UnknownTOTPMode is an unknown command
- UnknownTOTPMode Mode = iota
- // ShowTOTPMode will show the token
- ShowTOTPMode
- // ClipTOTPMode will copy to clipboard
- ClipTOTPMode
- // MinimalTOTPMode will display minimal information to display the token
- MinimalTOTPMode
- // ListTOTPMode lists the available tokens
- ListTOTPMode
- // OnceTOTPMode will only show the token once and exit
- OnceTOTPMode
- // URLTOTPMode will dump the URL details
- URLTOTPMode
- // SeedTOTPMode will show the TOTP URL seed
- SeedTOTPMode
-)
-
// NewDefaultTOTPOptions gets the default option set
func NewDefaultTOTPOptions(app CommandOptions) TOTPOptions {
return TOTPOptions{
@@ -93,11 +72,11 @@ func (w totpWrapper) generateCode() (string, error) {
func (args *TOTPArguments) display(opts TOTPOptions) error {
interactive := opts.IsInteractive()
- if args.Mode == MinimalTOTPMode || args.Mode == URLTOTPMode || args.Mode == SeedTOTPMode {
+ if args.Mode == commands.TOTPMinimal || args.Mode == commands.TOTPSeed || args.Mode == commands.TOTPURL {
interactive = false
}
- once := args.Mode == OnceTOTPMode
- clipMode := args.Mode == ClipTOTPMode
+ once := args.Mode == commands.TOTPOnce
+ clipMode := args.Mode == commands.TOTPClip
if !interactive && clipMode {
return errors.New("clipboard not available in non-interactive mode")
}
@@ -120,10 +99,10 @@ func (args *TOTPArguments) display(opts TOTPOptions) error {
wrapper.opts.Period = uint(k.Period())
writer := opts.app.Writer()
switch args.Mode {
- case SeedTOTPMode:
+ case commands.TOTPSeed:
fmt.Fprintln(writer, wrapper.code)
return nil
- case URLTOTPMode:
+ case commands.TOTPURL:
fmt.Fprintf(writer, "url: %s\n", k.URL())
fmt.Fprintf(writer, "seed: %s\n", wrapper.code)
fmt.Fprintf(writer, "digits: %s\n", wrapper.opts.Digits)
@@ -225,7 +204,7 @@ func (args *TOTPArguments) display(opts TOTPOptions) error {
// Do will perform the TOTP operation
func (args *TOTPArguments) Do(opts TOTPOptions) error {
- if args.Mode == UnknownTOTPMode {
+ if args.Mode == "" {
return ErrUnknownTOTPMode
}
if opts.Clear == nil || opts.CanTOTP == nil || opts.IsInteractive == nil {
@@ -234,7 +213,7 @@ func (args *TOTPArguments) Do(opts TOTPOptions) error {
if !opts.CanTOTP() {
return ErrNoTOTP
}
- if args.Mode == ListTOTPMode {
+ if args.Mode == commands.TOTPList {
return doList(kdbx.OTPField, args.Entry, opts.app, false)
}
return args.display(opts)
@@ -245,7 +224,7 @@ func NewTOTPArguments(args []string) (*TOTPArguments, error) {
if len(args) == 0 {
return nil, errors.New("not enough arguments for totp")
}
- opts := &TOTPArguments{Mode: UnknownTOTPMode}
+ opts := &TOTPArguments{}
sub := args[0]
needs := true
length := len(args)
@@ -258,22 +237,16 @@ func NewTOTPArguments(args []string) (*TOTPArguments, error) {
return nil, errors.New("list takes only a filter (if any)")
}
}
- opts.Mode = ListTOTPMode
case commands.TOTPURL:
- opts.Mode = URLTOTPMode
case commands.TOTPSeed:
- opts.Mode = SeedTOTPMode
case commands.TOTPShow:
- opts.Mode = ShowTOTPMode
case commands.TOTPClip:
- opts.Mode = ClipTOTPMode
case commands.TOTPMinimal:
- opts.Mode = MinimalTOTPMode
case commands.TOTPOnce:
- opts.Mode = OnceTOTPMode
default:
return nil, ErrUnknownTOTPMode
}
+ opts.Mode = sub
if needs {
if length != 2 {
return nil, errors.New("invalid arguments")
diff --git a/internal/app/totp_test.go b/internal/app/totp_test.go
@@ -93,35 +93,35 @@ func TestNewTOTPArgumentsErrors(t *testing.T) {
func TestNewTOTPArguments(t *testing.T) {
args, _ := app.NewTOTPArguments([]string{"ls"})
- if args.Mode != app.ListTOTPMode || args.Entry != "" {
+ if args.Mode != "ls" || args.Entry != "" {
t.Error("invalid args")
}
args, _ = app.NewTOTPArguments([]string{"ls", "xyz"})
- if args.Mode != app.ListTOTPMode || args.Entry != "xyz" {
+ if args.Mode != "ls" || args.Entry != "xyz" {
t.Error("invalid args")
}
args, _ = app.NewTOTPArguments([]string{"show", "test"})
- if args.Mode != app.ShowTOTPMode || args.Entry != "test" {
+ if args.Mode != "show" || args.Entry != "test" {
t.Error("invalid args")
}
args, _ = app.NewTOTPArguments([]string{"clip", "test"})
- if args.Mode != app.ClipTOTPMode || args.Entry != "test" {
+ if args.Mode != "clip" || args.Entry != "test" {
t.Error("invalid args")
}
args, _ = app.NewTOTPArguments([]string{"minimal", "test"})
- if args.Mode != app.MinimalTOTPMode || args.Entry != "test" {
+ if args.Mode != "minimal" || args.Entry != "test" {
t.Error("invalid args")
}
args, _ = app.NewTOTPArguments([]string{"once", "test"})
- if args.Mode != app.OnceTOTPMode || args.Entry != "test" {
+ if args.Mode != "once" || args.Entry != "test" {
t.Error("invalid args")
}
args, _ = app.NewTOTPArguments([]string{"url", "test"})
- if args.Mode != app.URLTOTPMode || args.Entry != "test" {
+ if args.Mode != "url" || args.Entry != "test" {
t.Error("invalid args")
}
args, _ = app.NewTOTPArguments([]string{"seed", "test"})
- if args.Mode != app.SeedTOTPMode || args.Entry != "test" {
+ if args.Mode != "seed" || args.Entry != "test" {
t.Error("invalid args")
}
}
@@ -131,7 +131,7 @@ func TestDoErrors(t *testing.T) {
if err := args.Do(app.TOTPOptions{}); err == nil || err.Error() != "unknown totp mode" {
t.Errorf("invalid error: %v", err)
}
- args.Mode = app.ShowTOTPMode
+ args.Mode = "show"
if err := args.Do(app.TOTPOptions{}); err == nil || err.Error() != "invalid option functions" {
t.Errorf("invalid error: %v", err)
}