summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-10-12 17:43:54 (EDT)
committer P. J. McDermott <pjm@nac.net>2013-10-12 17:43:54 (EDT)
commitefc27ba6b79a8d5a5ebf0fea8579740cc4f3cdd7 (patch)
tree1a1cb580445f1c7586aa9545a933e85c5b12cd48
parent7bda53cd534ee6b6604367cd4c2a45376d41c7df (diff)
Rewrite get_options() and refactor main().
-rw-r--r--src/pro-archman.sh42
1 files changed, 17 insertions, 25 deletions
diff --git a/src/pro-archman.sh b/src/pro-archman.sh
index a174187..05b076f 100644
--- a/src/pro-archman.sh
+++ b/src/pro-archman.sh
@@ -33,8 +33,6 @@ OPTSTRING='hVb:'
# Global variables
loading_cmd=
-opt_base_dir=
-opt_cmd=
base_dir=
conf_incoming_channel=
conf_incoming_dir=
@@ -86,30 +84,32 @@ use garbage
main()
{
+ local cmd=
local status=
load_locale
load_cmds
- opt_cmd=''
-
get_options "${@}"
shift $(($OPTIND - 1))
- if [ ${#} -lt 1 ] && [ "x${opt_cmd}" = 'x' ]; then
- cmd_help_main >&2
- exit 1
- fi
- base_dir="${opt_base_dir:-.}"
+ base_dir="${opt_b:-.}"
- if [ "x${opt_cmd}" != 'x' ]; then
- run_cmd "${opt_cmd}" "${@}"
- status=${?}
+ if ${opt_h:-false}; then
+ cmd='help'
+ elif ${opt_V:-false}; then
+ cmd='version'
+ elif [ ${#} -lt 1 ]; then
+ cmd_help_main >&2
+ exit 1
else
- run_cmd "${@}"
- status=${?}
+ cmd="${1}"
+ shift
fi
+ run_cmd "${cmd}" "${@}"
+ status=${?}
+
return ${status}
}
@@ -117,18 +117,10 @@ get_options()
{
local opt=
+ unset OPTARG
while getopts "${OPTSTRING}" opt; do
- case "${opt}" in
- 'b')
- opt_base_dir="$(cd "${OPTARG}" && pwd)"
- ;;
- 'h')
- opt_cmd='help'
- ;;
- 'V')
- opt_cmd='version'
- ;;
- esac
+ eval "opt_${opt}=\"\${OPTARG:-true}\""
+ unset OPTARG
done
return 0