commit 1afef3939f479adc1e738438ad478427963acbab
parent 2d8db959df1ff05dff21a6c65c381d7759fec039
Author: St John Karp <contact@stjo.hn>
Date: Sat, 26 Nov 2022 08:17:29 -0500
Separate the command parsing from the flag parsing
The commands are supposed to come first, so this will prevent
the command being superceded by a subsequent loop and will
let us fall back to a default command.
Diffstat:
M | balrog | | | 38 | ++++++++++++++++++++++---------------- |
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/balrog b/balrog
@@ -16,7 +16,29 @@ TMP_FILE="$HOME/.balrogtmp"
CLIP='waycopy' ||
CLIP='xclip -selection clipboard'
+# The first argument should be the command.
+
+case "$1" in
+ edit)
+ ACTION='edit'
+ shift
+ ;;
+ generate)
+ ACTION='generate'
+ shift
+ ;;
+ otp)
+ OTP=1
+ shift
+ ;;
+ show)
+ ACTION='show'
+ shift
+ ;;
+esac
+
# Loop through all the arguments and set flags/options.
+
while [ "$#" -gt 0 ] ; do
case "$1" in
-c|--clip)
@@ -31,22 +53,6 @@ while [ "$#" -gt 0 ] ; do
CHARACTERS='a-zA-Z0-9'
shift
;;
- edit)
- ACTION='edit'
- shift
- ;;
- generate)
- ACTION='generate'
- shift
- ;;
- otp)
- OTP=1
- shift
- ;;
- show)
- ACTION='show'
- shift
- ;;
*)
# Treat anything unidentified as the name of the password.
KEY="$1"