This commit is contained in:
Dict Xiong 2022-11-15 23:14:40 +08:00
parent b2a1896cb9
commit d485f1d8c2

View File

@ -102,25 +102,25 @@ if [[ "$EUID" != "0" && -x $(command -v sudo) ]]; then
SUDO='sudo' SUDO='sudo'
fi fi
# arg parse parse_arg()
ARG="" {
ARG_PARSED=() local ORIGIN_ARG ARG=""
while [[ $# > 0 || -n "$ARG" ]]; do ARG_PARSED=()
if [[ -z "$ARG" ]]; then ARG=$1 ORIGIN_ARG=$1; shift; fi while [[ $# > 0 || -n "$ARG" ]]; do
case $ARG in if [[ -z "$ARG" ]]; then ARG=$1 ORIGIN_ARG=$1; shift; fi
-q*|--quite ) export DFS_QUIET=1 ;; case $ARG in
--* ) ARG_PARSED+=("$ARG") ;; -q*|--quite ) export DFS_QUIET=1 ;;
-* ) ARG_PARSED+=("${ARG:0:2}") ;; --* ) ARG_PARSED+=("$ARG") ;;
* ) fmt_fatal "error parsing argument \"$ORIGIN_ARG\"" ;; -* ) ARG_PARSED+=("${ARG:0:2}") ;;
esac * ) fmt_fatal "error parsing argument \"$ORIGIN_ARG\"" ;;
if [[ "$ARG" == "--"* || ${#ARG} == 2 ]]; then esac
ARG="" if [[ "$ARG" == "--"* || ${#ARG} == 2 ]]; then
else ARG=""
ARG=-${ARG:2} else
fi ARG=-${ARG:2}
done fi
unset ARG ORIGIN_ARG done
}
ask_for_yN() ask_for_yN()
{ {
@ -190,4 +190,5 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
$1 "${@:2}" $1 "${@:2}"
else else
setup_color setup_color
parse_arg "$@"
fi fi