Add option parsing and change order of operations

This commit is contained in:
Case Duckworth 2020-05-23 19:49:20 -05:00
parent 40b7e1b98a
commit bcc28cfae8
1 changed files with 16 additions and 5 deletions

21
bollux
View File

@ -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