diff options
author | kate.ward <kate.ward@forestent.com> | 2013-01-07 22:10:49 +0000 |
---|---|---|
committer | kate.ward <kate.ward@forestent.com> | 2013-01-07 22:10:49 +0000 |
commit | 0a4f16fc4e9bcffa9732c057877aa42e59f0a95b (patch) | |
tree | 257f5ed86f8b593a8726249f042469b9eaa3f1cb | |
parent | a8cbe677c5163657e6a5a6f79454f079a0e38824 (diff) | |
download | shflags-0a4f16fc4e9bcffa9732c057877aa42e59f0a95b.tar.gz |
updated docs and unit test regarding the usage of boolean flags
-rw-r--r-- | source/1.0/src/shflags | 10 | ||||
-rwxr-xr-x | source/1.0/src/shflags_test_parsing.sh | 28 |
2 files changed, 22 insertions, 16 deletions
diff --git a/source/1.0/src/shflags b/source/1.0/src/shflags index 814f450..371bf3e 100644 --- a/source/1.0/src/shflags +++ b/source/1.0/src/shflags @@ -18,12 +18,10 @@ # # DEFINE_string: takes any input, and intreprets it as a string. # -# DEFINE_boolean: typically does not take any argument: say --myflag to set -# FLAGS_myflag to true, or --nomyflag to set FLAGS_myflag to false. -# Alternately, you can say -# --myflag=true or --myflag=t or --myflag=0 or -# --myflag=false or --myflag=f or --myflag=1 -# Passing an option has the same affect as passing the option once. +# DEFINE_boolean: does not take any arguments. Say --myflag to set +# FLAGS_myflag to true, or --nomyflag to set FLAGS_myflag to false. For short +# flags, passing the flag on the command-line negates the default value, i.e. +# if the default is true, passing the flag sets the value to false. # # DEFINE_float: takes an input and intreprets it as a floating point number. As # shell does not support floats per-se, the input is merely validated as diff --git a/source/1.0/src/shflags_test_parsing.sh b/source/1.0/src/shflags_test_parsing.sh index 0437de4..f585e96 100755 --- a/source/1.0/src/shflags_test_parsing.sh +++ b/source/1.0/src/shflags_test_parsing.sh @@ -47,23 +47,31 @@ testGetoptEnhanced() testValidBoolsShort() { - # flip flag to true FLAGS -b >"${stdoutF}" 2>"${stderrF}" rtrn=$? - assertTrue "FLAGS returned a non-zero result (${rtrn})" ${rtrn} + assertTrue "-b) FLAGS returned a non-zero result (${rtrn})" ${rtrn} value=${FLAGS_bool:-} - assertTrue "boolean was not true (${value})." "${value}" - assertFalse 'expected no output to STDERR' "[ -s '${stderrF}' ]" + assertTrue "-b) boolean was not true (${value})." "${value}" + assertFalse '-b) expected no output to STDERR' "[ -s '${stderrF}' ]" test ${rtrn} -eq ${FLAGS_TRUE} -a ! -s "${stderrF}" th_showOutput $? "${stdoutF}" "${stderrF}" - # verify that passing the option a second time leaves the flag true - FLAGS -b >"${stdoutF}" 2>"${stderrF}" + DEFINE_boolean bool2 true '2nd boolean' B + FLAGS >"${stdoutF}" 2>"${stderrF}" rtrn=$? - assertTrue "repeat: FLAGS returned a non-zero result (${rtrn})" ${rtrn} - value=${FLAGS_bool:-} - assertTrue "repeat: boolean was not true (${value})" ${value} - assertFalse 'repeat: expected no output to STDERR' "[ -s '${stderrF}' ]" + assertTrue "-B) FLAGS returned a non-zero result (${rtrn})" ${rtrn} + value=${FLAGS_bool2:-} + assertTrue "-B) boolean was not true (${value})" ${value} + assertFalse '-B) expected no output to STDERR' "[ -s '${stderrF}' ]" + test ${rtrn} -eq ${FLAGS_TRUE} -a ! -s "${stderrF}" + th_showOutput $? "${stdoutF}" "${stderrF}" + + FLAGS -B >"${stdoutF}" 2>"${stderrF}" + rtrn=$? + assertTrue "-B) FLAGS returned a non-zero result (${rtrn})" ${rtrn} + value=${FLAGS_bool2:-} + assertFalse "-B) boolean was not false (${value})" ${value} + assertFalse '-B) expected no output to STDERR' "[ -s '${stderrF}' ]" test ${rtrn} -eq ${FLAGS_TRUE} -a ! -s "${stderrF}" th_showOutput $? "${stdoutF}" "${stderrF}" } |