Permalink
Browse files

very long default values now wrap differently under enhanced getopt

git-svn-id: http://shflags.googlecode.com/svn/trunk/source/1.0@104 9d7cb843-df4f-0410-8a79-4785ae5a3405
  • Loading branch information...
1 parent 51a6dd5 commit bccdfd3f698b4c4547ffbbed51722323d71eef39 kate.ward@forestent.com committed Nov 17, 2008
Showing with 26 additions and 6 deletions.
  1. +13 −3 src/shflags
  2. +13 −3 src/shflags_test_public.sh
View
16 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
View
16 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}" )

0 comments on commit bccdfd3

Please sign in to comment.