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!"
}
BIN=install
parse_arg "$@"
FUNC=install
for i in ${ARG_PARSED[@]}; do
case $i in
-i ) BIN=install ;;
-r ) BIN=uninstall ;;
-i ) FUNC=install ;;
-r ) FUNC=uninstall ;;
-d|--dev ) export DFS_DEV=1 ;;
-l|--lite ) export DFS_LITE=1 ;;
-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
done
$BIN
$FUNC

View File

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