aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-08-26 14:12:52 +0200
committerMattias Andrée <maandree@operamail.com>2013-08-26 14:12:52 +0200
commit15213e550b15d8f68153c98b20d6c90bebef9361 (patch)
tree01e7d3a8518377412b184ee11ed51340ccf70ea8 /src
parentm bash (diff)
downloadargparser-15213e550b15d8f68153c98b20d6c90bebef9361.tar.gz
argparser-15213e550b15d8f68153c98b20d6c90bebef9361.tar.bz2
argparser-15213e550b15d8f68153c98b20d6c90bebef9361.tar.xz
fix bash version4.0
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r--src/argparser.bash59
-rwxr-xr-xsrc/test.bash2
2 files changed, 33 insertions, 28 deletions
diff --git a/src/argparser.bash b/src/argparser.bash
index 2cf062f..75a2f59 100644
--- a/src/argparser.bash
+++ b/src/argparser.bash
@@ -634,13 +634,7 @@ function args_parse
if [ "${args_alternative}" = 1 ] || (( ${#arg} > 2 )) && [ "${arg::1}" = "${arg:1:1}" ]; then
if [ ! $dontget = 0 ]; then
(( dontget-- ))
- elif [ ! -e "${args_optmap}/${arg}" ]; then
- (( args_unrecognised_count++ ))
- if (( args_unrecognised_count <= 5 )); then
- echo "${args_program}: warning: unrecognised option ${arg}" >> "${args_out}"
- fi
- rc=1
- else
+ elif [ -e "${args_optmap}/${arg}" ]; then
std="$(head -n 1 < "${args_optmap}/${arg}")"
type="$(head -n 2 < "${args_optmap}/${arg}" | tail -n 1)"
trigger="$(tail -n 1 < "${args_optmap}/${arg}")"
@@ -649,26 +643,6 @@ function args_parse
argqueue+=( "" )
nulqueue+=( 1 )
"$trigger" "${arg}" "${std}"
- elif [ ! "${arg/=/}" = "${arg}" ]; then
- _arg="${arg%%=*}"
- type="$(head -n 1 < "${args_optmap}/${_arg}" | tail -n 1)"
- if (( $type >= ${args_ARGUMENTED} )); then
- optqueue+=( "${_arg}" )
- argqueue+=( "${arg#*=}" )
- nulqueue+=( 0 )
- if [ $type = ${args_VARIADIC} ]; then
- dashed=1
- "$trigger" "${arg}" "${std}"
- else
- "$trigger" "${arg}" "${std}" "${arg#*=}"
- fi
- else
- (( args_unrecognised_count++ ))
- if (( args_unrecognised_count <= 5 )); then
- echo "${args_program}: warning: unrecognised option ${arg}" >> "${args_out}"
- fi
- rc=1
- fi
elif (( $type <= ${args_OPTARGUMENTED} )); then
optqueue+=( "${arg}" )
(( get++ ))
@@ -678,6 +652,37 @@ function args_parse
nulqueue+=( 1 )
dashed=1
fi
+ elif [ ! "${arg/=/}" = "${arg}" ]; then
+ type=x
+ _arg="${arg%%=*}"
+ if [ -e "${args_optmap}/${_arg}" ]; then
+ type="$(head -n 2 < "${args_optmap}/${_arg}" | tail -n 1)"
+ fi
+ if [ ! $type = x ] && (( $type >= ${args_ARGUMENTED} )); then
+ optqueue+=( "${_arg}" )
+ argqueue+=( "${arg#*=}" )
+ nulqueue+=( 0 )
+ std="$(head -n 1 < "${args_optmap}/${_arg}")"
+ trigger="$(tail -n 1 < "${args_optmap}/${_arg}")"
+ if [ $type = ${args_VARIADIC} ]; then
+ dashed=1
+ "$trigger" "${_arg}" "${std}"
+ else
+ "$trigger" "${_arg}" "${std}" "${arg#*=}"
+ fi
+ else
+ (( args_unrecognised_count++ ))
+ if (( args_unrecognised_count <= 5 )); then
+ echo "${args_program}: warning: unrecognised option ${_arg}" >> "${args_out}"
+ fi
+ rc=1
+ fi
+ else
+ (( args_unrecognised_count++ ))
+ if (( args_unrecognised_count <= 5 )); then
+ echo "${args_program}: warning: unrecognised option ${arg}" >> "${args_out}"
+ fi
+ rc=1
fi
else
sign="${_arg::1}"
diff --git a/src/test.bash b/src/test.bash
index 71e6137..3f45bae 100755
--- a/src/test.bash
+++ b/src/test.bash
@@ -50,7 +50,7 @@ args_add_argumentless '' 0 'Prints the text: hello world' --hello
args_add_argumentless '' 0 '' ++hidden
args_add_argumented '' 0 LINE 'Prints the choosen line' -l --line
-args_add_optargumented '' '' 0 LINE 'Prints the choosen line' -l --Line
+args_add_optargumented '' '' 0 LINE 'Prints the choosen line' -L --Line
args_add_variadic '' 0 LINE 'Prints the choosen lines' --l --lines
args_parse "$@"