Close #5 : Removed all calls to cut/grep

This commit is contained in:
2014-05-26 12:19:00 -07:00
parent d3721faf10
commit 7188ec557f

View File

@@ -102,8 +102,7 @@ function cmdarg_info
# Sets various flags about your script that are printed during cmdarg_usage # Sets various flags about your script that are printed during cmdarg_usage
# #
FLAGS="header|copyright|footer|author" FLAGS="header|copyright|footer|author"
echo "$1" | grep -E "$FLAGS" >/dev/null 2>&1 if [[ "$1" =~ $FLAGS ]]; then
if [ $? -ne 0 ]; then
echo "cmdarg_info <flag> <value>" >&2 echo "cmdarg_info <flag> <value>" >&2
echo "Where <flag> is one of $FLAGS" >&2 echo "Where <flag> is one of $FLAGS" >&2
${CMDARG_ERROR_BEHAVIOR} 1 ${CMDARG_ERROR_BEHAVIOR} 1
@@ -205,7 +204,7 @@ function cmdarg_validate
( ${CMDARG_VALIDATORS[${shortopt}]} "$value" "$hashkey") ( ${CMDARG_VALIDATORS[${shortopt}]} "$value" "$hashkey")
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Invalid value for -$shortopt : ${value}" >&2 echo "Invalid value for -$shortopt : ${value}" >&2
return 1 ${CMDARG_ERROR_BEHAVIOR} 1
fi fi
fi fi
return 0 return 0
@@ -303,8 +302,8 @@ function cmdarg_parse
shift shift
if [[ "${fullopt}" =~ ^(--[a-zA-Z0-9_\-]+|^-[a-zA-Z0-9])= ]]; then if [[ "${fullopt}" =~ ^(--[a-zA-Z0-9_\-]+|^-[a-zA-Z0-9])= ]]; then
tmpopt=$fullopt tmpopt=$fullopt
fullopt=$(echo "$tmpopt" | cut -d = -f 1) fullopt=${tmpopt%%=*}
optarg=$(echo "$tmpopt" | cut -d = -f 2) optarg=${tmpopt##*=}
is_equals_arg=0 is_equals_arg=0
fi fi