Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added check to prevent overriding reserved flags constants

git-svn-id: http://shflags.googlecode.com/svn/trunk/source/1.0@118 9d7cb843-df4f-0410-8a79-4785ae5a3405
  • Loading branch information...
commit d11ae6bc531a177401460d55f6e5feab368fa89b 1 parent 8720a92
kate.ward@forestent.com authored
Showing with 25 additions and 2 deletions.
  1. +3 −1 doc/CHANGES-1.0.txt
  2. +13 −1 src/shflags
  3. +9 −0 src/shflags_test_defines.sh
View
4 doc/CHANGES-1.0.txt
@@ -5,7 +5,7 @@ Changes with 1.0.3
------------------
MAJOR CHANGE! ``FLAGS_ARGC`` is now obsolete, and is replaced by
-``FLAGS_ARGV``.
+``FLAGS_ARGV``. See below for more info.
Fixed issue# 7 where long flags defined with '=' (e.g. --abc=123) made it
impossible for the user to know how many non-flag command-line arguments were
@@ -29,6 +29,8 @@ in the unit tests, and provides basically no benefit.
Fixed bug under Solaris where the generated help was adding extra 'x'
characters.
+Added checks for reserved flag variables (e.g. FLAGS_TRUE).
+
Changes with 1.0.2
------------------
View
14 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} \
View
9 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
#
Please sign in to comment.
Something went wrong with that request. Please try again.