Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
4 doc/CHANGES-1.0.txt
@@ -5,7 +5,7 @@ Changes with 1.0.3
5 5 ------------------
6 6
7 7 MAJOR CHANGE! ``FLAGS_ARGC`` is now obsolete, and is replaced by
8   -``FLAGS_ARGV``.
  8 +``FLAGS_ARGV``. See below for more info.
9 9
10 10 Fixed issue# 7 where long flags defined with '=' (e.g. --abc=123) made it
11 11 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.
29 29 Fixed bug under Solaris where the generated help was adding extra 'x'
30 30 characters.
31 31
  32 +Added checks for reserved flag variables (e.g. FLAGS_TRUE).
  33 +
32 34
33 35 Changes with 1.0.2
34 36 ------------------
14 src/shflags
@@ -33,7 +33,7 @@
33 33 #
34 34 # SPECIAL FLAGS: There are a few flags that have special meaning:
35 35 # --help (or -?) prints a list of all the flags in a human-readable fashion
36   -# --flagfile=foo read flags from foo.
  36 +# --flagfile=foo read flags from foo. (not implemented yet)
37 37 # -- as in getopt(), terminates flag-processing
38 38 #
39 39 # EXAMPLE USAGE:
@@ -80,10 +80,14 @@
80 80 [ -n "${FLAGS_VERSION:-}" ] && return 0
81 81 FLAGS_VERSION='1.0.3pre'
82 82
  83 +# return values
83 84 FLAGS_TRUE=0
84 85 FLAGS_FALSE=1
85 86 FLAGS_ERROR=2
86 87
  88 +# reserved flag names
  89 +FLAGS_RESERVED='ARGC ARGV ERROR FALSE HELP PARENT RESERVED TRUE VERSION'
  90 +
87 91 _flags_debug() { echo "flags:DEBUG $@" >&2; }
88 92 _flags_warn() { echo "flags:WARN $@" >&2; }
89 93 _flags_error() { echo "flags:ERROR $@" >&2; }
@@ -157,6 +161,7 @@ __flags_constants=`set |awk -F= '/^FLAGS_/ || /^__FLAGS_/ {print $1}'`
157 161 for __flags_const in ${__flags_constants}; do
158 162 # skip certain flags
159 163 case ${__flags_const} in
  164 + FLAGS_HELP) continue ;;
160 165 FLAGS_PARENT) continue ;;
161 166 esac
162 167 # set flag readonly
@@ -223,6 +228,13 @@ _flags_define()
223 228
224 229 # TODO(kward): check for validity of the flag name (e.g. dashes)
225 230
  231 + # check whether the flag name is reserved
  232 + echo " ${FLAGS_RESERVED} " |grep " ${_flags_name_} " >/dev/null
  233 + if [ $? -eq 0 ]; then
  234 + flags_error="flag name (${_flags_name_}) is reserved"
  235 + _flags_return_=${FLAGS_ERROR}
  236 + fi
  237 +
226 238 # require short option for getopt that don't support long options
227 239 if [ ${_flags_return_} -eq ${FLAGS_TRUE} \
228 240 -a ${__FLAGS_GETOPT_VERS} -ne ${__FLAGS_GETOPT_VERS_ENH} \
9 src/shflags_test_defines.sh
@@ -180,6 +180,15 @@ testShortNameLength()
180 180 :
181 181 }
182 182
  183 +testFlagNameIsReserved()
  184 +{
  185 + ( DEFINE_string TRUE '' 'true is a reserved flag name' t \
  186 + >"${stdoutF}" 2>"${stderrF}" )
  187 + rtrn=$?
  188 + assertEquals ${FLAGS_ERROR} ${rtrn}
  189 + th_showOutput ${rtrn} "${stdoutF}" "${stderrF}"
  190 +}
  191 +
183 192 #------------------------------------------------------------------------------
184 193 # suite functions
185 194 #

0 comments on commit d11ae6b

Please sign in to comment.
Something went wrong with that request. Please try again.