| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function cli_doParseArgumentsCommon { |
| |
| local -a SHORT |
| local -a LONG |
| local -a REQUIRED |
| local ARGUMENT='' |
| local ARGUMENTS_DEFAULT='' |
| local COMMONS='' |
| local COMMON='' |
| local ARGSS='' |
| local ARGSL='' |
| local PATTERN='' |
| local COUNT=0 |
| |
| |
| SHORT[0]='f' |
| SHORT[1]='q' |
| SHORT[2]='y' |
| SHORT[3]='c' |
| |
| |
| LONG[0]='filter' |
| LONG[1]='quiet' |
| LONG[2]='answer' |
| LONG[3]='dont-commit-changes' |
| |
| |
| |
| |
| REQUIRED[0]=':' |
| REQUIRED[1]='' |
| REQUIRED[2]=':' |
| REQUIRED[3]='' |
| |
| |
| |
| |
| |
| |
| ARGUMENTS_DEFAULT=$ARGUMENTS |
| |
| |
| for ARGUMENT in $ARGUMENTS_DEFAULT;do |
| |
| while [[ $COUNT -lt ${#LONG[*]} ]];do |
| |
| |
| PATTERN="^'(--${LONG[$COUNT]}|-${SHORT[$COUNT]})" |
| |
| |
| if [[ $ARGUMENT =~ "${PATTERN}" ]];then |
| if [[ $COMMONS == '' ]];then |
| COMMONS="${ARGUMENT}" |
| else |
| COMMONS="${COMMONS} ${ARGUMENT}" |
| fi |
| fi |
| |
| |
| COUNT=$(($COUNT + 1)) |
| |
| done |
| |
| |
| COUNT=0 |
| |
| done |
| |
| |
| |
| |
| |
| eval set -- "$COMMONS" |
| |
| |
| |
| cli_doParseArgumentsReDef "$@" |
| |
| |
| |
| |
| while [[ $COUNT -lt ${#LONG[*]} ]];do |
| |
| |
| if [[ $ARGSS == '' ]];then |
| ARGSS=${SHORT[$COUNT]}${REQUIRED[$COUNT]} |
| else |
| ARGSS="${ARGSS},${SHORT[$COUNT]}${REQUIRED[$COUNT]}" |
| fi |
| |
| |
| if [[ $ARGSL == '' ]];then |
| ARGSL=${LONG[$COUNT]}${REQUIRED[$COUNT]} |
| else |
| ARGSL="${ARGSL},${LONG[$COUNT]}${REQUIRED[$COUNT]}" |
| fi |
| |
| |
| COUNT=$(($COUNT + 1)) |
| |
| done |
| |
| |
| cli_doParseArguments |
| |
| |
| |
| eval set -- "$ARGUMENTS" |
| |
| |
| while true; do |
| case "$1" in |
| |
| --filter ) |
| FLAG_FILTER="$2" |
| shift 2 |
| ;; |
| |
| --quiet ) |
| FLAG_QUIET="true" |
| shift 1 |
| ;; |
| |
| --answer ) |
| FLAG_ANSWER="$2" |
| shift 2 |
| ;; |
| |
| --dont-commit-changes ) |
| FLAG_DONT_COMMIT_CHANGES="true" |
| shift 1 |
| ;; |
| |
| * ) |
| break |
| ;; |
| esac |
| done |
| |
| |
| |
| |
| if [[ ${COMMONS} != '' ]];then |
| |
| |
| |
| |
| |
| COMMONS=$(echo ${COMMONS} | sed -r 's!(\(|\[|\{|\.|\+|\*)!\\\1!g') |
| |
| |
| |
| |
| for COMMON in ${COMMONS};do |
| ARGUMENTS_DEFAULT=$(echo ${ARGUMENTS_DEFAULT} | sed -r "s!${COMMON}!!g") |
| done |
| |
| fi |
| |
| |
| eval set -- "${ARGUMENTS_DEFAULT}" |
| |
| |
| cli_doParseArgumentsReDef "$@" |
| |
| } |