From efc27ba6b79a8d5a5ebf0fea8579740cc4f3cdd7 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 12 Oct 2013 17:43:54 -0400 Subject: Rewrite get_options() and refactor main(). --- (limited to 'src') 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 -- cgit v0.9.1