1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

Merge pull request #1230 from ailin-nemui/fix-clang-format-xs-opts

fix clang-format-xs option parser by using getopt
This commit is contained in:
ailin-nemui 2020-10-27 10:39:25 +01:00 committed by GitHub
commit e0292665c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,58 +9,60 @@ CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
options=() options=()
files=() files=()
lines=() lines=()
no_options=0;inplace=0;xml=0;keep_offset=0;keep_length=0;keep=0; inplace=0;xml=0;
filename=tmp.1.c filename=tmp.1.c
offsets= offsets=
karg=
off_opts=() off_opts=()
for arg in "$@"; do opts=$(getopt -n clang-format-xs -s bash -a -o in -l Werror,assume-filename:,cursor:,dry-run,dump-config,fallback-style:,ferror-limit:,help,length:,lines:,offset:,output-replacement-xmls,sort-includes,style:,verbose,version -- "$@")
if [[ $keep = 1 ]]; then if [ $? -ne 0 ]; then exit 1; fi
if [[ "$karg" = "-offset" ]]; then eval set -- "$opts"; unset opts
offsets="$offsets${offsets:+ }$arg" while :; do
off_opts+=("$karg" "$arg") case "$1" in
elif [[ "$karg" = "-length" ]]; then --offset)
offsets="$offsets:$arg" offsets="$offsets${offsets:+ }$2"
off_opts+=("$karg" "$arg") off_opts+=("$1" "$2")
elif [[ "$karg" = "-assume-filename" ]]; then shift 2
filename="$arg" continue
options+=("$karg" "$arg")
else
options+=("$karg" "$arg")
fi
keep=0
elif [[ $no_options = 0 ]]; then
case "$arg" in
-assume-filename=*)
filename="${arg#-assume-filename=}"
;; ;;
-lines=*) --length)
lines+=("${arg#-lines=}") offsets="$offsets:$2"
off_opts+=("$1" "$2")
shift 2
continue
;;
--assume-filename)
filename="$2"
options+=("$1" "$2")
shift 2
continue
;;
--lines)
lines+=("$2")
shift 2
continue
;;
--output-replacements-xml)
xml=1
shift
continue
;;
-i)
inplace=1
shift
continue
;;
--)
shift
break
;; ;;
*) *)
options+=("$1")
shift
continue
;; ;;
esac esac
case "$arg" in
--) no_options=1
;;
-i) inplace=1
;;
-output-replacements-xml)
xml=1
;;
-offset|-length|-cursor|-assume-filename|-fallback-style|-style)
keep=1
karg="$arg"
;;
-*) options+=("$arg")
;;
*) files+=("$arg")
;;
esac
else
files+=("$arg")
fi
done done
files=("$@")
export IN_LINES="${lines[*]}" export IN_LINES="${lines[*]}"
export OFFSETS="$offsets" export OFFSETS="$offsets"