new argument parser

This commit is contained in:
Jack L. Frost 2015-02-01 17:33:10 +03:00
parent fcb4c6bdb0
commit 909fc31f46

38
sup
View File

@ -93,26 +93,36 @@ sup.mktemp() {
} }
sup.getopt() { sup.getopt() {
local keys while (( $# )); do
unset -v arg opt c keys
for i in "$@"; do case "$1" in
case "$i" in (--) printf '%s\n' '--'; break;;
--*) echo "$i";;
-*) (--*)
keys=( $(echo "${i##*-}" | fold -w1) ) IFS='=' read arg opt <<< "$1"
printf '%s\n' "$arg"
if [[ "${#keys[@]}" -gt 1 ]]; then [[ "$opt" ]] && {
for k in "${keys[@]}"; do printf '%s\n' "$opt"
echo "-${k}" }
done
else
echo "$i"
fi
;; ;;
*) echo "$i";; (-*)
while read -n1 c
do
case "$c" in
-|'') :;;
*) keys+=( "-$c" );;
esac
done <<< "$1"
printf '%s\n' "${keys[@]}"
;;
(*) printf '%s\n' "$1";;
esac esac
shift
done done
} }