woo proper handling

This commit is contained in:
Jack L. Frost 2015-02-09 16:22:26 +03:00
parent 34775cfe97
commit bf18623e06

101
zpac
View File

@ -142,6 +142,41 @@ abs.get() {
svn checkout "svn://svn.archlinux.org/${svn_repo}/${1}/trunk" "${cfg_workdir}/${1}"
}
args_norm() {
declare arg opt c
declare -g argv
while (( $# )); do
unset -v arg opt c
case "$1" in
(--) argv+=( "$1" ); break;;
(--*)
IFS='=' read arg opt <<< "$1"
argv+=( "$arg" )
[[ "$opt" ]] && {
argv+=( "$opt" )
}
;;
(-*)
while read -n1 c
do
case "$c" in
-|'') :;;
*) argv+=( "-$c" );;
esac
done <<< "$1"
;;
(*) argv+=( "$1" );;
esac
shift
done
}
main() {
if [[ -f "$HOME/.config/zpac.rc.sh" ]]; then
source "$HOME/.config/zpac.rc.sh"
@ -151,43 +186,34 @@ main() {
case "$1" in
(--) shift; break;;
(-h) usage; return 0;;
(-s) action='search';;
(-A)
action='search'
flag_search_aur=1;;
(-S)
action='search'
flag_search_syncdb=1;;
(-d)
if [[ "$action" == 'get' ]]; then
flag_get_deps=1
else
action='get'
fi
;;
(-w)
cfg_workdir="$2"
shift;;
(-f) flag_force=1;;
(-*)
while read -n1 c
do
case "$c" in
(-|'') :;;
(h) usage; return 0;;
(s) action='search';;
(A)
action='search'
flag_search_aur=1;;
(S)
action='search'
flag_search_syncdb=1;;
(d)
if [[ "$action" == 'get' ]]; then
flag_get_deps=1
else
action='get'
fi
;;
(w)
cfg_workdir="$2"
shift;;
(f) flag_force=1;;
(*)
err "Unknown key: $1"
usage
return 1
;;
esac
done <<< "$1"
err "Unknown key: $1"
usage
return 1
;;
(*) break;;
@ -273,4 +299,5 @@ main() {
esac
}
main "$@"
args_norm "$@"
main "${argv[@]}"