diff options
author | kate.ward <kate.ward@forestent.com> | 2009-04-01 14:09:23 +0000 |
---|---|---|
committer | kate.ward <kate.ward@forestent.com> | 2009-04-01 14:09:23 +0000 |
commit | 39913d13e3ffb8bacd009155c0f51241dde3659b (patch) | |
tree | fff65fb0160e04844de5f679c2f2e4deaad590f7 /source/1.0/src | |
parent | ccb66b4f8bc5a592ace60035a7a5e409b4729d71 (diff) | |
download | shflags-39913d13e3ffb8bacd009155c0f51241dde3659b.tar.gz |
added check to prevent overriding reserved flags constants
Diffstat (limited to 'source/1.0/src')
-rw-r--r-- | source/1.0/src/shflags | 14 | ||||
-rwxr-xr-x | source/1.0/src/shflags_test_defines.sh | 9 |
2 files changed, 22 insertions, 1 deletions
diff --git a/source/1.0/src/shflags b/source/1.0/src/shflags index eff46f6..6546be3 100644 --- a/source/1.0/src/shflags +++ b/source/1.0/src/shflags @@ -33,7 +33,7 @@ # # SPECIAL FLAGS: There are a few flags that have special meaning: # --help (or -?) prints a list of all the flags in a human-readable fashion -# --flagfile=foo read flags from foo. +# --flagfile=foo read flags from foo. (not implemented yet) # -- as in getopt(), terminates flag-processing # # EXAMPLE USAGE: @@ -80,10 +80,14 @@ [ -n "${FLAGS_VERSION:-}" ] && return 0 FLAGS_VERSION='1.0.3pre' +# return values FLAGS_TRUE=0 FLAGS_FALSE=1 FLAGS_ERROR=2 +# reserved flag names +FLAGS_RESERVED='ARGC ARGV ERROR FALSE HELP PARENT RESERVED TRUE VERSION' + _flags_debug() { echo "flags:DEBUG $@" >&2; } _flags_warn() { echo "flags:WARN $@" >&2; } _flags_error() { echo "flags:ERROR $@" >&2; } @@ -157,6 +161,7 @@ __flags_constants=`set |awk -F= '/^FLAGS_/ || /^__FLAGS_/ {print $1}'` for __flags_const in ${__flags_constants}; do # skip certain flags case ${__flags_const} in + FLAGS_HELP) continue ;; FLAGS_PARENT) continue ;; esac # set flag readonly @@ -223,6 +228,13 @@ _flags_define() # TODO(kward): check for validity of the flag name (e.g. dashes) + # check whether the flag name is reserved + echo " ${FLAGS_RESERVED} " |grep " ${_flags_name_} " >/dev/null + if [ $? -eq 0 ]; then + flags_error="flag name (${_flags_name_}) is reserved" + _flags_return_=${FLAGS_ERROR} + fi + # require short option for getopt that don't support long options if [ ${_flags_return_} -eq ${FLAGS_TRUE} \ -a ${__FLAGS_GETOPT_VERS} -ne ${__FLAGS_GETOPT_VERS_ENH} \ diff --git a/source/1.0/src/shflags_test_defines.sh b/source/1.0/src/shflags_test_defines.sh index 569156d..8c54aa8 100755 --- a/source/1.0/src/shflags_test_defines.sh +++ b/source/1.0/src/shflags_test_defines.sh @@ -180,6 +180,15 @@ testShortNameLength() : } +testFlagNameIsReserved() +{ + ( DEFINE_string TRUE '' 'true is a reserved flag name' t \ + >"${stdoutF}" 2>"${stderrF}" ) + rtrn=$? + assertEquals ${FLAGS_ERROR} ${rtrn} + th_showOutput ${rtrn} "${stdoutF}" "${stderrF}" +} + #------------------------------------------------------------------------------ # suite functions # |