Commit 6156737d authored by Creak's avatar Creak
Browse files

Simplify the options parser

parent 971fcc52
......@@ -7,12 +7,26 @@ funkwhale_version="${FUNKWHALE_VERSION-$funkwhale_version_default}"
funkwhale_hostname=""
funkwhale_protocol="https"
# Params:
# 1. message
function die
{
echo "$1" >&2
exit 1
}
# Params:
# 1. option, in the format "key=value"
function get_not_empty_arg
{
value=${1#*=}
if [ -z $value ]; then
die "ERROR: \"${1%%=*}\" requires a non-empty option argument."
fi
echo $value
}
function show_help
{
bin_name=$(basename $0)
......@@ -54,32 +68,26 @@ while true; do
exit
;;
-h|--host)
if [ "$2" ]; then
if [ -n "$2" ]; then
funkwhale_hostname=$2
shift
else
die "ERROR: \"$1\" requires a non-empty option argument."
fi
;;
--host=?*)
funkwhale_hostname=${1#*=}
;;
--host=)
die "ERROR: \"$1\" requires a non-empty option argument."
--host=*)
funkwhale_hostname=$(get_not_empty_arg $1)
;;
-p|--protocol)
if [ "$2" ]; then
if [ -n "$2" ]; then
funkwhale_protocol=$2
shift
else
die "ERROR: \"$1\" requires a non-empty option argument."
fi
;;
--protocol=?*)
funkwhale_protocol=${1#*=}
;;
--protocol=)
die "ERROR: \"$1\" requires a non-empty option argument."
--protocol=*)
funkwhale_protocol=$(get_not_empty_arg $1)
;;
-?*)
echo "ERROR: Unknown option: $1" >&2
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment