diff options
author | kate.ward <kate.ward@forestent.com> | 2008-07-11 20:32:11 +0000 |
---|---|---|
committer | kate.ward <kate.ward@forestent.com> | 2008-07-11 20:32:11 +0000 |
commit | f08c5b68b8288af85aaf99c7ab404027da14e5d6 (patch) | |
tree | 954a2759f5ec32090794b3d64185ac2a0501108c | |
parent | 58da2019dbac58c62ca8763e34e9e99addff0e8e (diff) | |
download | shflags-f08c5b68b8288af85aaf99c7ab404027da14e5d6.tar.gz |
fixed help flag definition in zsh 3.0.8
-rw-r--r-- | source/1.0/doc/CHANGES-1.0.txt | 5 | ||||
-rw-r--r-- | source/1.0/src/shflags | 9 | ||||
-rwxr-xr-x | source/1.0/src/shflags_test_public.sh | 16 |
3 files changed, 16 insertions, 14 deletions
diff --git a/source/1.0/doc/CHANGES-1.0.txt b/source/1.0/doc/CHANGES-1.0.txt index 2d55d64..c09506e 100644 --- a/source/1.0/doc/CHANGES-1.0.txt +++ b/source/1.0/doc/CHANGES-1.0.txt @@ -14,6 +14,11 @@ Upgraded shUnit2 to 2.1.4 Added unit testing for the help output. +When including a library (e.g. shflags) in a script, zsh 3.0.8 doesn't actually +execute the code in-line, but later. As such, variables that are defined in the +library cannot be used until functions are called from the main code. This +required the 'help' flag definition to be moved inside the FLAGS command. + Changes with 1.0.0 ------------------ diff --git a/source/1.0/src/shflags b/source/1.0/src/shflags index 0e34287..5a01f3e 100644 --- a/source/1.0/src/shflags +++ b/source/1.0/src/shflags @@ -520,6 +520,9 @@ FLAGS() { _flags_return=${FLAGS_TRUE} + # define standard 'help' flag + DEFINE_boolean 'help' false 'show this help' 'h' + FLAGS_ARGC=0 _flags_shortOpts=`_flags_genOptStr ${__FLAGS_OPTSTR_SHORT}` _flags_longOpts='' # generated later only when needed @@ -829,9 +832,6 @@ flags_reset() __flags_longNames=' ' __flags_shortNames=' ' - # define standard 'help' flag - DEFINE_boolean 'help' false 'show this help' 'h' - unset _flags_name _flags_type _flags_strToEval } @@ -839,9 +839,6 @@ flags_reset() # main # -# define standard 'help' flag -DEFINE_boolean 'help' false 'show this help' 'h' - # restore the previous set of shell flags for _flags_shellFlag in ${__FLAGS_SHELL_FLAGS}; do echo ${_flags_oldShellFlags} |grep ${_flags_shellFlag} >/dev/null || \ diff --git a/source/1.0/src/shflags_test_public.sh b/source/1.0/src/shflags_test_public.sh index 933e596..5bdceb0 100755 --- a/source/1.0/src/shflags_test_public.sh +++ b/source/1.0/src/shflags_test_public.sh @@ -78,16 +78,16 @@ testStandardHelpOutput() DEFINE_boolean test_bool false 'test boolean' b DEFINE_string test_str '' 'test string' s - FLAGS_HELP='USAGE: standard [flags] args' + help='USAGE: standard [flags] args' cat >"${expectedF}" <<EOF USAGE: standard [flags] args flags: - -h show this help -b test boolean -s test string + -h show this help EOF - ( FLAGS -h >"${stdoutF}" 2>"${stderrF}" ) + ( FLAGS_HELP=${help}; FLAGS -h >"${stdoutF}" 2>"${stderrF}" ) diff "${expectedF}" "${stderrF}" >/dev/null rtrn=$? assertTrue 'unexpected help output' ${rtrn} @@ -102,16 +102,16 @@ testEnhancedHelpOutput() DEFINE_boolean test_bool false 'test boolean' b DEFINE_string test_str '' 'test string' s - FLAGS_HELP='USAGE: enhanced [flags] args' + help='USAGE: standard [flags] args' cat >"${expectedF}" <<EOF USAGE: enhanced [flags] args flags: - -h,--[no]help: show this help -b,--[no]test_bool: test boolean -s,--test_str: test string + -h,--[no]help: show this help EOF - ( FLAGS -h >"${stdoutF}" 2>"${stderrF}" ) + ( FLAGS_HELP=${help}; FLAGS -h >"${stdoutF}" 2>"${stderrF}" ) diff "${expectedF}" "${stderrF}" >/dev/null rtrn=$? assertTrue 'short flag help; unexpected help output' ${rtrn} @@ -125,11 +125,11 @@ EOF cat >"${expectedF}" <<EOF USAGE: enhanced [flags] args flags: - -h,--[no]help: show this help -b,--[no]test_bool: test boolean -s,--test_str: test string + -h,--[no]help: show this help EOF - ( FLAGS --help >"${stdoutF}" 2>"${stderrF}" ) + ( FLAGS_HELP=${help}; FLAGS --help >"${stdoutF}" 2>"${stderrF}" ) diff "${expectedF}" "${stderrF}" >/dev/null rtrn=$? assertTrue 'long flag help; unexpected help output' ${rtrn} |