diff options
author | kate.ward <kate.ward@forestent.com> | 2008-11-17 17:36:14 +0000 |
---|---|---|
committer | kate.ward <kate.ward@forestent.com> | 2008-11-17 17:36:14 +0000 |
commit | 6409961395c61690bbf8ebd2bf47448086a15039 (patch) | |
tree | f3db95cf874bbad9d304a9356d761bde100f956b | |
parent | 129a5d997476ff6ea37ea09bc25b32c8dd714be1 (diff) | |
download | shflags-6409961395c61690bbf8ebd2bf47448086a15039.tar.gz |
very long default values now wrap differently under enhanced getopt
-rw-r--r-- | source/1.0/src/shflags | 16 | ||||
-rwxr-xr-x | source/1.0/src/shflags_test_public.sh | 16 |
2 files changed, 26 insertions, 6 deletions
diff --git a/source/1.0/src/shflags b/source/1.0/src/shflags index fa511d7..894869e 100644 --- a/source/1.0/src/shflags +++ b/source/1.0/src/shflags @@ -935,13 +935,23 @@ flags_help() if [ ${flags_helpStrLen_} -lt ${flags_columns_} ]; then echo "${flags_helpStr_}" >&2 else + echo " ${flags_flagStr_} ${flags_help_}" >&2 # note: the silliness with the x's is purely for ksh93 on Ubuntu 6.06. # the sed strips the x's back out, plus the zero byte at the end of the - # string passed by echo (a C thing...). + # string passed by echo (C strings are zero byte terminated). flags_emptyStr_="`echo \"x${flags_flagStr_}x\" |tr -c '' ' ' \ |sed 's/...$//'`" - echo " ${flags_flagStr_} ${flags_help_}" >&2 - echo " ${flags_emptyStr_} ${flags_defaultStr_}" >&2 + flags_helpStr_=" ${flags_emptyStr_} ${flags_defaultStr_}" + flags_helpStrLen_=`expr "${flags_helpStr_}" : '.*'` + if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_STD} \ + -o ${flags_helpStrLen_} -lt ${flags_columns_} ]; then + # indented to match help string + echo "${flags_helpStr_}" >&2 + else + # indented four from left to allow for longer defaults as long flag + # names might be used too, making things too long + echo " ${flags_defaultStr_}" >&2 + fi fi done fi diff --git a/source/1.0/src/shflags_test_public.sh b/source/1.0/src/shflags_test_public.sh index 5364a28..e985155 100755 --- a/source/1.0/src/shflags_test_public.sh +++ b/source/1.0/src/shflags_test_public.sh @@ -69,7 +69,10 @@ testStandardHelpOutput() DEFINE_integer test_int 0 'test integer' i DEFINE_string test_str '' 'test string' s DEFINE_string long_desc 'blah' \ - 'testing of a long description to force wrap of default value' l + 'testing of a long description to force wrap of default value' D + DEFINE_string long_default \ + 'this_is_a_really_long_default_value_to_force_alternate_indentation' \ + 'testing of long default value' F help='USAGE: standard [flags] args' cat >"${expectedF}" <<EOF @@ -78,8 +81,10 @@ flags: -b test boolean (default: false) -i test integer (default: 0) -s test string (default: '') - -l testing of a long description to force wrap of default value + -D testing of a long description to force wrap of default value (default: 'blah') + -F testing of long default value + (default: 'this_is_a_really_long_default_value_to_force_alternate_indentation') -h show this help (default: false) EOF ( FLAGS_HELP=${help}; FLAGS -h >"${stdoutF}" 2>"${stderrF}" ) @@ -98,6 +103,9 @@ testEnhancedHelpOutput() DEFINE_string test_str '' 'test string' s DEFINE_string long_desc 'blah' \ 'testing of a long description to force wrap of default value' l + DEFINE_string long_default \ + 'this_is_a_really_long_default_value_to_force_alternate_indentation' \ + 'testing of long default value' F help='USAGE: enhanced [flags] args' cat >"${expectedF}" <<EOF @@ -106,8 +114,10 @@ flags: -b,--[no]test_bool: test boolean (default: false) -i,--test_int: test integer (default: 0) -s,--test_str: test string (default: '') - -l,--long_desc: testing of a long description to force wrap of default value + -D,--long_desc: testing of a long description to force wrap of default value (default: 'blah') + -F,--long_default: testing of long default value + (default: 'this_is_a_really_long_default_value_to_force_alternate_indentation') -h,--[no]help: show this help (default: false) EOF ( FLAGS_HELP=${help}; FLAGS -h >"${stdoutF}" 2>"${stderrF}" ) |