Better argument handling.

This commit is contained in:
Jack L. Frost 2015-01-31 18:45:47 +03:00
parent aa8929ff8e
commit 7d778ecd66

57
zpac
View File

@ -18,10 +18,10 @@ usage() {
Flags: Flags:
-h Show this message. -h Show this message.
-s Search for <package>. -s Search for <package>.
-S Search only in the sync db. Implies -s. -S Search only in the sync db. Implies -s.
-A Search only in AUR. Implies -s. -A Search only in AUR. Implies -s.
-d Get the package sources (default). -d Get the package sources (default).
-D Get the dependencies also. Implies -d. Set twice to also get the dependencies.
EOF EOF
} }
@ -112,6 +112,44 @@ abs.get() {
svn checkout "svn://svn.archlinux.org/${svn_repo}/${1}/trunk" "${cfg_workdir}/${1}" svn checkout "svn://svn.archlinux.org/${svn_repo}/${1}/trunk" "${cfg_workdir}/${1}"
} }
args_norm() {
while (( $# )); do
unset -v arg opt c keys
case "$1" in
--) shift; break;;
--*)
IFS='=' read arg opt <<< "$1"
printf '%s\n' "$arg"
[[ "$opt" ]] && {
printf '%s\n' "$opt"
}
;;
-*)
while read -n1 c
do
case "$c" in
-|'') :;;
*) keys+=( "-$c" );;
esac
done <<< "$1"
printf '%s\n' "${keys[@]}"
;;
esac
[[ "$2" && ! "$2" =~ ^- ]] && {
printf '%s\n' "$2"
shift
}
shift
done
}
main() { main() {
if [[ -f "$HOME/.config/zpac.rc.sh" ]]; then if [[ -f "$HOME/.config/zpac.rc.sh" ]]; then
source "$HOME/.config/zpac.rc.sh" source "$HOME/.config/zpac.rc.sh"
@ -129,10 +167,13 @@ main() {
action='search' action='search'
flag_search_syncdb=1;; flag_search_syncdb=1;;
(-d) action='get';; (-d)
(-D) if [[ "$action" == 'get' ]]; then
action='get' flag_get_deps=1
flag_get_deps=1;; else
action='get'
fi
;;
(--) shift; break;; (--) shift; break;;
(-*) (-*)
@ -224,4 +265,4 @@ main() {
esac esac
} }
main "$@" main $(args_norm "$@")