Fixes #4 : Make cmdarg understand '--option=value|-o=value' syntax.
This commit is contained in:
19
cmdarg.sh
19
cmdarg.sh
@@ -230,7 +230,7 @@ function cmdarg_parse
|
|||||||
#
|
#
|
||||||
# Call it EXACTLY LIKE THAT, and it will parse your arguments for you.
|
# Call it EXACTLY LIKE THAT, and it will parse your arguments for you.
|
||||||
# This function only knows about the arguments that you previously called 'cmdarg' for.
|
# This function only knows about the arguments that you previously called 'cmdarg' for.
|
||||||
local OPTIND parsing fullopt opt optarg longopt
|
local OPTIND parsing fullopt opt optarg longopt tmpopt
|
||||||
|
|
||||||
parsing=0
|
parsing=0
|
||||||
while [[ "$@" != "" ]]; do
|
while [[ "$@" != "" ]]; do
|
||||||
@@ -238,7 +238,15 @@ function cmdarg_parse
|
|||||||
opt=""
|
opt=""
|
||||||
longopt=""
|
longopt=""
|
||||||
fullopt=$1
|
fullopt=$1
|
||||||
|
is_equals_arg=1
|
||||||
shift
|
shift
|
||||||
|
if [[ "${fullopt}" =~ ^(--[a-zA-Z0-9_\-]+|^-[a-zA-Z0-9])= ]]; then
|
||||||
|
tmpopt=$fullopt
|
||||||
|
fullopt=$(echo "$tmpopt" | cut -d = -f 1)
|
||||||
|
optarg=$(echo "$tmpopt" | cut -d = -f 2)
|
||||||
|
is_equals_arg=0
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$fullopt" == "--" ]] && [[ $parsing -eq 0 ]]; then
|
if [[ "$fullopt" == "--" ]] && [[ $parsing -eq 0 ]]; then
|
||||||
cmdarg_argv+=($@)
|
cmdarg_argv+=($@)
|
||||||
break
|
break
|
||||||
@@ -263,9 +271,12 @@ function cmdarg_parse
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${CMDARG_FLAGS[$opt]} -eq $CMDARG_FLAG_REQARG ]] || [[ ${CMDARG_FLAGS[$opt]} -eq ${CMDARG_FLAG_OPTARG} ]]; then
|
if [[ $is_equals_arg -eq 1 ]]; then
|
||||||
optarg=$1
|
if [[ ${CMDARG_FLAGS[$opt]} -eq $CMDARG_FLAG_REQARG ]] || \
|
||||||
shift
|
[[ ${CMDARG_FLAGS[$opt]} -eq ${CMDARG_FLAG_OPTARG} ]]; then
|
||||||
|
optarg=$1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ${CMDARG["${opt}"]+abc} ]; then
|
if [ ${CMDARG["${opt}"]+abc} ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user