commit 3cacfc98ff2f92d6fafff4786970840bd331e42c
parent ede69542f37439e6ec3fa580c9622596598c6aaf
Author: Sean Enck <sean@ttypty.com>
Date: Thu, 13 Oct 2022 18:11:17 -0400
not all commands require a transaction to do things
Diffstat:
2 files changed, 39 insertions(+), 24 deletions(-)
diff --git a/cmd/main.go b/cmd/main.go
@@ -65,7 +65,6 @@ func printUsage() {
fmt.Println("lb usage:")
printCommand(clipCommand, "entry", "copy the entry's value into the clipboard")
printCommand(envCommand, "", "display environment variable information")
- printSubCommand(inputs.DefaultsCommand, "", "display the default environment values, exclude current settings")
printCommand(findCommand, "criteria", "perform a simplistic text search over the entry keys")
printCommand(helpCommand, "", "show this usage information")
printCommand(insertCommand, "entry", "insert a new entry into the store")
@@ -90,8 +89,6 @@ func internalCallback(name string) callbackFunction {
return hashText
case clearCommand:
return clearClipboard
- case envCommand:
- return inputs.ListEnvironmentVariables
}
return nil
}
@@ -115,16 +112,52 @@ func main() {
}
}
+func processInfoCommands(command string, args []string) (bool, error) {
+ switch command {
+ case helpCommand:
+ printUsage()
+ case envCommand:
+ printValues := true
+ invalid := false
+ switch len(args) {
+ case 2:
+ break
+ case 3:
+ if args[2] == "-defaults" {
+ printValues = false
+ } else {
+ invalid = true
+ }
+ default:
+ invalid = true
+ }
+ if invalid {
+ return false, errors.New("invalid argument")
+ }
+ inputs.ListEnvironmentVariables(printValues)
+ default:
+ return false, nil
+ }
+ return true, nil
+}
+
func run() *programError {
args := os.Args
if len(args) < 2 {
return newError("missing arguments", errors.New("requires subcommand"))
}
+ command := args[1]
+ ok, err := processInfoCommands(command, args)
+ if err != nil {
+ return newError("invalid command", err)
+ }
+ if ok {
+ return nil
+ }
t, err := backend.NewTransaction()
if err != nil {
return newError("unable to build transaction model", err)
}
- command := args[1]
switch command {
case listCommand, findCommand:
opts := backend.QueryOptions{}
@@ -259,8 +292,6 @@ func run() *programError {
if err := clipboard.CopyTo(existing.Value); err != nil {
return newError("clipboard failed", err)
}
- case helpCommand:
- printUsage()
default:
if len(args) < 2 {
return newError("command missing required arguments", fmt.Errorf("%s missing argument", command))
diff --git a/internal/inputs/env.go b/internal/inputs/env.go
@@ -38,9 +38,7 @@ const (
// ClipPasteEnv allows overriding the clipboard paste command
ClipPasteEnv = clipBaseEnv + "PASTE"
// ClipCopyEnv allows overriding the clipboard copy command
- ClipCopyEnv = clipBaseEnv + "COPY"
- // DefaultsCommand will get the environment values WITHOUT current environment settings
- DefaultsCommand = "-defaults"
+ ClipCopyEnv = clipBaseEnv + "COPY"
isYes = "yes"
isNo = "no"
defaultTOTPField = "totp"
@@ -259,20 +257,7 @@ func (o environmentOutput) printEnvironmentVariable(required bool, name, val, de
}
// ListEnvironmentVariables will print information about env variables and potential/set values
-func ListEnvironmentVariables(args []string) error {
- showValues := true
- switch len(args) {
- case 0:
- break
- case 1:
- if args[0] == DefaultsCommand {
- showValues = false
- } else {
- return errors.New("unknown argument")
- }
- default:
- return errors.New("too many arguments")
- }
+func ListEnvironmentVariables(showValues bool) {
e := environmentOutput{showValues: showValues}
e.printEnvironmentVariable(true, StoreEnv, "", "directory to the database file", []string{"file"})
e.printEnvironmentVariable(true, keyModeEnv, commandKeyMode, "how to retrieve the database store password", []string{commandKeyMode, plainKeyMode})
@@ -288,5 +273,4 @@ func ListEnvironmentVariables(args []string) error {
e.printEnvironmentVariable(false, ClipPasteEnv, "", "override the detected platform copy command", []string{commandArgsExample})
e.printEnvironmentVariable(false, clipMaxEnv, fmt.Sprintf("%d", defaultMaxClipboard), "override the amount of time before totp clears the clipboard (e.g. 10), must be an integer", []string{"integer"})
e.printEnvironmentVariable(false, PlatformEnv, "", "override the detected platform", []string{MacOSPlatform, LinuxWaylandPlatform, LinuxXPlatform, WindowsLinuxPlatform})
- return nil
}