summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorCraig Silverstein <csilvers+gflags@google.com>2008-07-22 23:29:39 +0000
committerCraig Silverstein <csilvers+gflags@google.com>2008-07-22 23:29:39 +0000
commitc79c32d98c4dc705ecc2fea2d7e8712afb6938fb (patch)
tree1972e016e139b225cf71ea8b2f4c34ba0af82932 /doc
parent83911c12f3a570c86c6d2c957ddd49be3bcb07ac (diff)
downloadgflags-c79c32d98c4dc705ecc2fea2d7e8712afb6938fb.tar.gz
gflags-c79c32d98c4dc705ecc2fea2d7e8712afb6938fb.tar.bz2
gflags-c79c32d98c4dc705ecc2fea2d7e8712afb6938fb.zip
Mon Jul 21 23:01:38 2008 Google Inc. <opensource@google.com>
* google-gflags: version 0.9 * Add the ability to validate a command-line flag (csilvers) * Add completion support for commandline flags in bash (daven) * Add -W compile flags to Makefile, when using gcc (csilvers) * Allow helpstring to be NULL (cristianoc) * Improved documentation of classes in the .cc file (csilvers) * Fix python bug with AppendFlagValues + shortnames (jjtswan) * Use bool instead of int for boolean flags in gflags.py (bcmills) * Simplify the way we declare flags, now more foolproof (csilvers) * Better error messages when bool flags collide (colohan) * Only evaluate DEFINE_foo macro args once (csilvers) git-svn-id: https://gflags.googlecode.com/svn/trunk@23 6586e3c6-dcc4-952a-343f-ff74eb82781d
Diffstat (limited to 'doc')
-rw-r--r--doc/gflags.html32
1 files changed, 32 insertions, 0 deletions
diff --git a/doc/gflags.html b/doc/gflags.html
index e059a7b..5ac362b 100644
--- a/doc/gflags.html
+++ b/doc/gflags.html
@@ -189,6 +189,38 @@ file.
<code>#include</code> will make explicit the dependency between the
two files. This causes the flag to be a global variable.</p>
+
+<h2> <A name=validate>RegisterFlagValidator: Sanity-checking Flag Values</A> </h2>
+
+<p>After DEFINE-ing a flag, you may optionally register a validator
+function with the flag. If you do this, after the flag is parsed from
+the commandline, and whenever its value is changes via a call to
+<code>SetCommandLineOption()</code>, the validator function is called
+with the new value as an argument. The validator function should
+return 'true' if the flag value is valid, and false otherwise.
+
+<p>Here is an example use of this functionality:</p>
+<pre>
+static bool ValidatePort(const char* flagname, int32 value) {
+ if (value > 0 && value < 32768) // value is ok
+ return true;
+ printf("Invalid value for --%s: %d\n", flagname, (int)value);
+ return false;
+}
+DEFINE_int32(port, 0, "What port to listen on");
+static const bool port_dummy = RegisterFlagValidator(&FLAGS_port, &ValidatePort);
+</pre>
+
+<p>By doing the registration at global initialization time (right
+after the DEFINE), we ensure that the registration happens before
+the commandline is parsed at the beginning of <code>main()</code>.</p>
+
+<p><code>RegisterFlagValidator()</code> returns true if the
+registration is successful. It return false if the registration fails
+because a) the first argument does not refer to a commandline flag, or
+b) a different validator has already been registered for this flag.</p>
+
+
<h2> <A name=together>Putting It Together: How to Set Up Flags</A> </h2>
<p>The final piece is the one that tells the executable to process the