diff options
author | Bo Ørsted Andresen <bo.andresen@zlin.dk> | 2007-03-07 09:22:11 +0000 |
---|---|---|
committer | Bo Ørsted Andresen <bo.andresen@zlin.dk> | 2007-03-07 09:22:11 +0000 |
commit | ebda88b51ded8521deeb4af6350de86f3ab49047 (patch) | |
tree | fc9edb0cdaad3881d5b28dfca5b8b26a1e5a060c | |
parent | 52ccd6677df8f8a7e570c8292c0844b8d41afb22 (diff) | |
download | wgetpaste-ebda88b51ded8521deeb4af6350de86f3ab49047.tar.gz |
Allow short options to be grouped. Convert --long-opt=foo to --long-opt foo.
-rwxr-xr-x | wgetpaste | 53 |
1 files changed, 19 insertions, 34 deletions
@@ -367,16 +367,29 @@ convert_to_raw() { ### read cli options +# convert groups of short options to singular short options. convert long options to short options. +for arg in "${@}"; do + if [[ "${arg}" =~ ^--.*= ]]; then + ARGS[${#ARGS[*]}]="${arg%=*}" + ARGS[${#ARGS[*]}]="${arg#*=}" + elif [[ "${arg}" =~ ^-- ]]; then + ARGS[${#ARGS[*]}]="${arg}" + elif [[ "${arg}" =~ ^- ]]; then + for short_arg in $(echo "${arg#-}" | sed 's|.| -&|g'); do + ARGS[${#ARGS[*]}]="${short_arg}" + done + else + ARGS[${#ARGS[*]}]="${arg}" + fi +done + +# set the converted options as input +set -- "${ARGS[@]}" + # if you know a better option (like getopts) which provides the same features # please let me know how. while [[ ! -z "${1}" ]]; do case "${1}" in - --command=* ) - [[ -z "${1#*=}" ]] && show_usage 1>&2 && exit 1 - SOURCE="command" - COMMANDS[${#COMMANDS[*]}]="${1#*=}" - shift - ;; -c | --command ) [[ -z "${2}" ]] && show_usage 1>&2 && exit 1 SOURCE="command" @@ -388,22 +401,11 @@ while [[ ! -z "${1}" ]]; do set -x shift ;; - --description=* ) - [[ -z "${1#*=}" ]] && show_usage 1>&2 && exit 1 - DESCRIPTION="${1#*=}" - shift - ;; -d | --description ) [[ -z "${2}" ]] && show_usage 1>&2 && exit 1 DESCRIPTION="${2}" shift 2 ;; - --expiration=* ) - [[ -z "${1#*=}" ]] && show_usage 1>&2 && exit 1 - EXPIRATION_SET=true - EXPIRATION="${1#*=}" - shift - ;; -e | --expiration ) [[ -z "${2}" ]] && show_usage 1>&2 && exit 1 EXPIRATION_SET=true @@ -426,12 +428,6 @@ while [[ ! -z "${1}" ]]; do SOURCE="info" shift ;; - --language=* ) - [[ -z "${1#*=}" ]] && show_usage 1>&2 && exit 1 - LANGUAGE_SET=true - LANGUAGE="${1#*=}" - shift - ;; -l | --language ) [[ -z "${2}" ]] && show_usage 1>&2 && exit 1 LANGUAGE_SET=true @@ -442,11 +438,6 @@ while [[ ! -z "${1}" ]]; do LIST_LANGUAGES=true shift ;; - --nick=* ) - [[ -z "${1#*=}" ]] && show_usage 1>&2 && exit 1 - NICK="$(escape "${1#*=}")" - shift - ;; -n | --nick ) [[ -z "${2}" ]] && show_usage 1>&2 && exit 1 NICK="$(escape "${2}")" @@ -456,12 +447,6 @@ while [[ ! -z "${1}" ]]; do RAW=true shift ;; - --service=* ) - [[ -z "${1#*=}" ]] && show_usage 1>&2 && exit 1 - verify_service "${1#*=}" - SERVICE="$(escape "${1#*=}")" - shift - ;; -s | --service ) [[ -z "${2}" ]] && show_usage 1>&2 && exit 1 verify_service "${2}" |