Handle arguments with getopt: it supports arguments with spaces.

This commit is contained in:
Jack L. Frost 2015-02-06 11:25:36 +03:00
parent c8b1f67bdd
commit 3d148e6b4a

37
zpac
View File

@ -22,6 +22,7 @@ usage() {
-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).
Set twice to also get the dependencies. Set twice to also get the dependencies.
-f Force downloading package sources even if they are already present in the working directory.
EOF EOF
} }
@ -81,14 +82,14 @@ aur.get() {
cd "$cfg_workdir" cd "$cfg_workdir"
echo "Downloading ${cfg_aur_url}${tarball_path}" echo "Working in ${cfg_workdir}"
echo "Downloading ${pkg_base}"
{ curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || { { curl -skL "${cfg_aur_url}${tarball_path}" | gzip -d | tar x; } || {
err "Fail!" err "Fail!"
return 1 return 1
} }
echo ": ${cfg_workdir}/${pkg_base}"
if (( flag_get_deps )); then if (( flag_get_deps )); then
unset depends makedepends unset depends makedepends
@ -104,6 +105,8 @@ aur.get() {
aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" ) aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" )
if (( aur_deps_count )); then if (( aur_deps_count )); then
echo "Getting dependencies for ${pkg_base}."
aur_deps=( $( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" ) ) aur_deps=( $( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" ) )
for i in "${aur_deps[@]}"; do for i in "${aur_deps[@]}"; do
@ -174,19 +177,20 @@ main() {
source "$HOME/.config/zpac.rc.sh" source "$HOME/.config/zpac.rc.sh"
fi fi
while (( $# )); do while getopts 'sASdw:f' opt
case "$1" in do
(-h) usage; return 0;; case "$opt" in
(h) usage; return 0;;
(-s) action='search';; (s) action='search';;
(-A) (A)
action='search' action='search'
flag_search_aur=1;; flag_search_aur=1;;
(-S) (S)
action='search' action='search'
flag_search_syncdb=1;; flag_search_syncdb=1;;
(-d) (d)
if [[ "$action" == 'get' ]]; then if [[ "$action" == 'get' ]]; then
flag_get_deps=1 flag_get_deps=1
else else
@ -194,19 +198,16 @@ main() {
fi fi
;; ;;
(-f) flag_force=1;; (w) cfg_workdir="$OPTARG";;
(f) flag_force=1;;
(--) shift; break;; (\?)
(-*) err "Unknown key: $OPTARG"
err "Unknown key: $1"
usage usage
return 1 return 1
;; ;;
*) break;;
esac esac
shift done shift $(( OPTIND - 1 ))
done
(( flag_search_aur && flag_search_syncdb )) && { (( flag_search_aur && flag_search_syncdb )) && {
unset flag_search_aur flag_search_syncdb unset flag_search_aur flag_search_syncdb