File tree Expand file tree Collapse file tree 3 files changed +19
-8
lines changed
Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -21,3 +21,16 @@ func (e CommandError) Error() string {
2121func resourceNotFoundError (name string ) CommandError {
2222 return CommandError {Message : name + " does not exist" }
2323}
24+
25+ // FlagError is an error during flag parsing.
26+ type FlagError struct {
27+ Message string
28+ }
29+
30+ func (e FlagError ) Error () string {
31+ return "flag error: %s" + e .Message
32+ }
33+
34+ func invalidAlgorithmError (value string ) FlagError {
35+ return FlagError {Message : "Invalid algorithm: " + value }
36+ }
Original file line number Diff line number Diff line change 11package cmd
22
33import (
4- "fmt"
5-
64 "github.com/urfave/cli/v2"
75 "github.com/yitsushi/totp-cli/internal/storage"
86)
@@ -12,9 +10,9 @@ func flagAlgorithm() *cli.StringFlag {
1210 Name : "algorithm" ,
1311 Value : "sha1" ,
1412 Usage : "Algorithm to use for HMAC (sha1, sha256, sha512)." ,
15- Action : func (ctx * cli.Context , value string ) error {
13+ Action : func (_ * cli.Context , value string ) error {
1614 if value != "sha1" && value != "sha256" && value != "sha512" {
17- return fmt . Errorf ( "Invalid algorithm: %s" , value )
15+ return invalidAlgorithmError ( value )
1816 }
1917
2018 return nil
Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ const DefaultTokenLength = 6
66
77// Account represents a TOTP account.
88type Account struct {
9- Name string `json:"name" yaml:"name"`
10- Token string `json:"token" yaml:"token"`
11- Prefix string `json:"prefix" yaml:"prefix"`
12- Length uint `json:"length" yaml:"length"`
9+ Name string `json:"name" yaml:"name"`
10+ Token string `json:"token" yaml:"token"`
11+ Prefix string `json:"prefix" yaml:"prefix"`
12+ Length uint `json:"length" yaml:"length"`
1313 Algorithm string `json:"algorithm" yaml:"algorithm"`
1414}
You can’t perform that action at this time.
0 commit comments