bug fix. now common.sh won't parse arg autoly

This commit is contained in:
Dict Xiong 2022-11-16 00:24:48 +08:00
parent d485f1d8c2
commit 4ff071f322
2 changed files with 10 additions and 10 deletions

View File

@ -256,15 +256,16 @@ uninstall(){
fmt_note "done uninstalling!" fmt_note "done uninstalling!"
} }
BIN=install parse_arg "$@"
FUNC=install
for i in ${ARG_PARSED[@]}; do for i in ${ARG_PARSED[@]}; do
case $i in case $i in
-i ) BIN=install ;; -i ) FUNC=install ;;
-r ) BIN=uninstall ;; -r ) FUNC=uninstall ;;
-d|--dev ) export DFS_DEV=1 ;; -d|--dev ) export DFS_DEV=1 ;;
-l|--lite ) export DFS_LITE=1 ;; -l|--lite ) export DFS_LITE=1 ;;
-a|--auto ) install_dependencies ;; -a|--auto ) install_dependencies ;;
* ) fmt_warning "unknown command \"$ORIGIN_ARG\". available: -i, -r, -q, -d, -l, -a"; exit 1 ;; * ) fmt_fatal "unknown option \"$i\". available: -i, -r, -q, -d, -l, -a" ;;
esac esac
done done
$BIN $FUNC

View File

@ -104,17 +104,17 @@ fi
parse_arg() parse_arg()
{ {
local ORIGIN_ARG ARG="" local ARG=""
ARG_PARSED=() ARG_PARSED=()
while [[ $# > 0 || -n "$ARG" ]]; do while [[ $# > 0 || -n "$ARG" ]]; do
if [[ -z "$ARG" ]]; then ARG=$1 ORIGIN_ARG=$1; shift; fi if [[ -z "$ARG" ]]; then ARG=$1; shift; fi
case $ARG in case $ARG in
-q*|--quite ) export DFS_QUIET=1 ;; -q*|--quite ) export DFS_QUIET=1 ;;
--* ) ARG_PARSED+=("$ARG") ;; --* ) ARG_PARSED+=("$ARG") ;;
-* ) ARG_PARSED+=("${ARG:0:2}") ;; -* ) ARG_PARSED+=("${ARG:0:2}") ;;
* ) fmt_fatal "error parsing argument \"$ORIGIN_ARG\"" ;; * ) ARG_PARSED+=("$ARG") ;;
esac esac
if [[ "$ARG" == "--"* || ${#ARG} == 2 ]]; then if [[ "$ARG" == "--"* || ! "$ARG" == "-"* || ${#ARG} -le 2 ]]; then
ARG="" ARG=""
else else
ARG=-${ARG:2} ARG=-${ARG:2}
@ -190,5 +190,4 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
$1 "${@:2}" $1 "${@:2}"
else else
setup_color setup_color
parse_arg "$@"
fi fi