Add option parsing and change order of operations
authorCase Duckworth <acdw@acdw.net>
Sun, 24 May 2020 00:49:20 +0000 (19:49 -0500)
committerCase Duckworth <acdw@acdw.net>
Sun, 24 May 2020 00:49:20 +0000 (19:49 -0500)
bollux

diff --git a/bollux b/bollux
index b319e9d..079c83b 100755 (executable)
--- a/bollux
+++ b/bollux
@@ -347,18 +347,26 @@ bollux() {
        request "$URL" | handle "$URL"
 }
 
+process_cmdline() {
+       while getopts :hL: OPT; do
+               case "$OPT" in
+               h) bollux_usage ;;
+               L) LOGL="$OPTARG" ;;
+               :) die 1 "Option -$OPTARG requires an argument" ;;
+               *) die 1 "Unknown option: -$OPTARG" ;;
+               esac
+       done
+}
+
 bollux_setup() {
-       mkfifo .resource
-       trap bollux_cleanup INT QUIT TERM EXIT
+       trap bollux_cleanup INT QUIT EXIT
 }
 
 bollux_cleanup() {
        echo
-       rm -f .resource
 }
 
 if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
-       set -euo pipefail # strict mode
        # requirements here -- so they're only checked once
        require gawk
        require dd
@@ -366,6 +374,9 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
        require openssl
        require sed
 
+       bollux_setup
+
        bollux "$@"
-       echo
+
+       bollux_cleanup
 fi