From 909fc31f46ef27e80b37472ca3bf508869142d73 Mon Sep 17 00:00:00 2001 From: fbt Date: Sun, 1 Feb 2015 17:33:10 +0300 Subject: [PATCH 1/2] new argument parser --- sup | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/sup b/sup index fe2cb5f..ecd4687 100755 --- a/sup +++ b/sup @@ -93,26 +93,36 @@ sup.mktemp() { } sup.getopt() { - local keys + while (( $# )); do + unset -v arg opt c keys - for i in "$@"; do - case "$i" in - --*) echo "$i";; + case "$1" in + (--) printf '%s\n' '--'; break;; - -*) - keys=( $(echo "${i##*-}" | fold -w1) ) + (--*) + IFS='=' read arg opt <<< "$1" + printf '%s\n' "$arg" - if [[ "${#keys[@]}" -gt 1 ]]; then - for k in "${keys[@]}"; do - echo "-${k}" - done - else - echo "$i" - fi + [[ "$opt" ]] && { + printf '%s\n' "$opt" + } ;; - *) echo "$i";; + (-*) + while read -n1 c + do + case "$c" in + -|'') :;; + *) keys+=( "-$c" );; + esac + done <<< "$1" + + printf '%s\n' "${keys[@]}" + ;; + + (*) printf '%s\n' "$1";; esac + shift done } From 9695ac5418a329aafb26eb302f8f922d7bce95e9 Mon Sep 17 00:00:00 2001 From: fbt Date: Sun, 1 Feb 2015 17:34:26 +0300 Subject: [PATCH 2/2] Fail if no file is available --- sup | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sup b/sup index ecd4687..e22f5f1 100755 --- a/sup +++ b/sup @@ -163,6 +163,11 @@ main() { } else file="$target" + + [[ -f "$file" ]] || { + sup.err "No such file: ${file}" + return 1 + } fi fi