Fixed a bug where cmdarg_argv is not populated without --

This commit is contained in:
2014-01-09 10:34:47 -05:00
parent 77698f430c
commit fa34368592
2 changed files with 8 additions and 0 deletions

View File

@@ -198,6 +198,11 @@ Similarly, cmdarg understands '--' which means "stop processing arguments, the r
... Cmdarg would parse -x and --longopt as expected, and then ${cmdarg_argv[0]} would hold "--some-thing-with-dashes", for your program to do with what it will. ... Cmdarg would parse -x and --longopt as expected, and then ${cmdarg_argv[0]} would hold "--some-thing-with-dashes", for your program to do with what it will.
getopt vs getopts
=================
cmdarg does not use getopt or getopts for option parsing. Its parser is written in 100% pure bash, and is self contained in cmdarg_parse. It will run the same way anywhere you have bash4.
Tests Tests
===== =====

View File

@@ -243,6 +243,9 @@ function cmdarg_parse
elif [[ "${fullopt:0:1}" == "-" ]] && [[ ${#fullopt} -eq 2 ]]; then elif [[ "${fullopt:0:1}" == "-" ]] && [[ ${#fullopt} -eq 2 ]]; then
opt=${fullopt:1} opt=${fullopt:1}
longopt=${CMDARG[$opt]} longopt=${CMDARG[$opt]}
elif [[ "${fullopt:0:1}" != "-" ]]; then
cmdarg_argv+=("$fullopt")
continue
else else
echo "Malformed argument: ${fullopt}" >&2 echo "Malformed argument: ${fullopt}" >&2
echo "While parsing: $@" >&2 echo "While parsing: $@" >&2