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() {
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
}