commit 9a6874b2cc200946d61f2c40cbf5d1d9de3727b4
parent fd5ec7e36b44a5ddb402091e562a0a1184cca874
Author: Sean Enck <sean@ttypty.com>
Date: Mon, 18 Jul 2022 19:01:52 -0400
simplify this logic a bit
Diffstat:
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/cmd/lb-totp/main.go b/cmd/lb-totp/main.go
@@ -32,15 +32,12 @@ func clear() {
}
}
-func totpToken(f store.FileSystem, extension bool) string {
+func totpEnv() string {
t := os.Getenv("LOCKBOX_TOTP")
if t == "" {
t = "totp"
}
- if !extension {
- return t
- }
- return f.NewFile(t)
+ return t
}
func display(token string, args cli.Arguments) error {
@@ -59,7 +56,7 @@ func display(token string, args cli.Arguments) error {
return err
}
f := store.NewFileSystemStore()
- tok := filepath.Join(strings.TrimSpace(token), totpToken(f, false))
+ tok := filepath.Join(strings.TrimSpace(token), totpEnv())
pathing := f.NewPath(tok)
if !misc.PathExists(pathing) {
return errors.New("object does not exist")
@@ -158,7 +155,7 @@ func main() {
options := cli.ParseArgs(cmd)
if options.List {
f := store.NewFileSystemStore()
- token := totpToken(f, true)
+ token := f.NewFile(totpEnv())
results, err := f.List(store.ViewOptions{ErrorOnEmpty: true, Filter: func(path string) string {
if filepath.Base(path) == token {
return filepath.Dir(f.CleanPath(path))