projcet url:
https://github.com/schuhschuh/gflags

usage: commandline flags processing



DEFINE: Defining Flags In Program

DEFINE_bool: boolean

DEFINE_int32: 32-bit integer

DEFINE_int64: 64-bit integer

DEFINE_uint64: unsigned 64-bit integer

DEFINE_double: double

DEFINE_string: C++ string



DECLARE: Using the Flag in a Different File

If the flag does span multiple files, DECLARE it in theassociated .h file, and make others #include that .h file if they want to access the flag. The #include will make explicit
the dependency between the two files. This causes the flag to be a global variable.



RegisterFlagValidator: Sanity-checking Flag Values

Here is an example use of this functionality:

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);

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 main().



Putting It Together: How to Set Up Flags

gflags::ParseCommandLineFlags(&argc, &argv, true);

The last argument is called "remove_flags".
If true, then ParseCommandLineFlags removes the flags and their arguments from argv, and modifies argc appropriately
. In this case, after the function call, argv will hold only commandline arguments, and not commandline
flags.

If, on the other hand, remove_flags is false, then ParseCommandLineFlags will leave argc unchanged, butwill rearrange the arguments in argv so that the flags are all at the beginning.



Setting Flags on the Command Line

Here's an example of all the ways to specify the "languages" flag:

app_containing_foo --languages="chinese,japanese,korean"

app_containing_foo -languages="chinese,japanese,korean"

app_containing_foo --languages "chinese,japanese,korean"

app_containing_foo -languages "chinese,japanese,korean"

For boolean flags, the possibilities are slightly different:

app_containing_foo --big_menu

app_containing_foo --nobig_menu

app_containing_foo --big_menu=true

app_containing_foo --big_menu=false



Changing the Default Flag Value

It's simple to do this: just assign a new value to the flag in main(), before calling ParseCommandLineFlags():

   DECLARE_bool(lib_verbose);   // mylib has a lib_verbose flag, default is false

   int main(int argc, char** argv) {

     FLAGS_lib_verbose = true;  // in my app, I want a verbose lib by default

     ParseCommandLineFlags(...);

   }

For this application, users can still set the flag value on the commandline, but if they do not, the flag's value will default to true.



Special Flags

--helpshows all flags from all files, sorted by file and then by name; shows the flagname, its default value,
and its help string

--helpfullsame as -help, but unambiguously asks for all flags (in case -help changes in the future)

--helpshortshows only flags for the file with the same name as the executable (usually the one containing main())

--helpxmllike --help, but output is in xml for easier parsing

--helpon=FILE  shows only flags defined in FILE.*

--helpmatch=Sshows only flags defined in *S*.*

--helppackageshows flags defined in files in same directory as main()

--versionprints version info for the executable

--fromenv

--fromenv=foo,bar says to read the values for the foo and bar flags from the environment.

--tryfromenv

--tryfromenv is exactly like --fromenv, except it is not a fatal error to say --tryfromenv=foo if FLAGS_foo is not actually defined in the environment.

--flagfile

--flagfile=f tells the commandlineflags module to read the file f, and to run all the flag-assignments found in that file as if these flags had been specified on the commandline.



The API

For more information about these routines, and other useful helper methods such asgflags::SetUsageMessage() andgflags::SetVersionString,
seegflags.h.



Miscellaneous Notes

If your application has code like this:

   #define STRIP_FLAG_HELP 1    // this must go before the #include!

   #include <gflags/gflags.h>

we will remove the help messages from the compiled source. This canreduce the size of the resulting binary somewhat, and mayalso be useful for
security reasons
.

gflags摘记的更多相关文章

  1. gflags

    一.安装配置 下载地址: https://code.google.com/p/gflags/downloads/list 解压安装: tar zxvf gflags-2.0.tar.gz && ...

  2. 使用PageHeap.EXE或GFlags.EXE检查内存越界错误 (转)

    2011-05-27 20:19 290人阅读 评论(0) 收藏 举报 microsoftdebuggingstructureoutputimagefile 必先利其器之一:使用PageHeap.EX ...

  3. google gflags使用.

    code.google.com 被墙的好开心... gflags很简单. 编译使用都很简单. (不像omaha这种丧心病狂的编译依赖). cmake 生成一下. 一路顺风顺水. 值得注意的是:  默认 ...

  4. glog摘记

    projcet url:https://code.google.com/p/google-glog/ usage: application-level logging setting flags GL ...

  5. 使用PageHeap.EXE或GFlags.EXE检查内存越界错误

    必先利其器之一:使用PageHeap.EXE或GFlags.EXE检查内存越界错误 Article last modified on 2002-6-3 ------------------------ ...

  6. Windbg的gflags.exe -- Attach调试利器

    有没有碰到过程序启动就因为异常直接crash?有没有碰到程序启动之后什么反应也没有?有没有碰到过程序启动之后去触发另一个进程失败?有没有碰到别人的程序调用了你的代码,出现问题以后,让你来调查,而你只有 ...

  7. gflags 学习

    一.下载 https://github.com/gflags/gflags 二.可以将gflags编译成lib 三.在需要的工程的workspace下面引入编译好的gflags动态库,在库里面写好BU ...

  8. linux下gflags的安装

    gflags是google开发的一套命令行参数解析工具,被很多软件系统所依赖,应该算是一个基础的库,安装其实很简单,但是如果在网上找的一些教程大部分都是安装后不能被其他软件调用的,因为默认使用cmak ...

  9. gflags命令行参数解析

    gflags库是google开源的命令行参数解析工具. 安装 官方没有提供二进制库,但是Debian/Ubuntu平台本身提供了二进制库,可以直接git clone https://github.co ...

随机推荐

  1. overlay实现容器跨主机通信

    本节内容: Docker容器跨主机通信方案 环境信息 升级内核 安装docker 防火墙设置和开启内核转发 安装启动consul 启动Docker 创建overlay network 创建容器 测试容 ...

  2. CF 586B 起点到终点的最短路和次短路之和

    起点是右下角  终点是左上角 每次数据都是两行的点  输入n 表示有n列 接下来来的2行是 列与列之间的距离 最后一行是  行之间的距离 枚举就行   Sample test(s) input 41 ...

  3. HBase(九)HBase表以及Rowkey的设计

    一 命名空间 1 命名空间的结构 1) Table:表,所有的表都是命名空间的成员,即表必属于某个命名空间,如果没有指定, 则在 default 默认的命名空间中. 2) RegionServer g ...

  4. 流程设计器jQuery + svg/vml(Demo7 - 设计器与引擎及表单一起应用例子)

    去年就完成了流程设计器及流程引擎的开发,本想着把流程设计器好好整理一下,形成一个一步一步的开发案例,结果才整理了一点点,发现写文章比写代码还累,加上有事情要忙,结果就.. 明天要去外包驻场了,现把流程 ...

  5. 【LOJ】#2558. 「LNOI2014」LCA

    题解 当年LN还是有专门的省选题的,但是还不如没有 看到这道题,我就想到了一个清晰易懂,简单好写,代码优美的树链剖分线段树套主席树的\(O(q\log^{3}n)\)做法,且就5组数据出题人肯定是不会 ...

  6. C#实现盛大盛付通充值卡状态查询

    今天有这样一需求,要求能够查询盛付通卡的状态,官网如下 http://www.801335.com/status/index.htm 刚一打开网址,发现两个输入框加一个验证码,心中一喜不是小  cas ...

  7. bzoj 1202: [HNOI2005]狡猾的商人

    我居然用暴力跑过去了... 思路:两个区间合成一个新的区间才会产生冲突, 我们用并查集维护前缀和, 0 - n 个节点分别表示sum[ 0 ] - sum[ n ], d[ i ] 表示 前缀i 和它 ...

  8. WMRouter:美团外卖Android开源路由框架

    WMRouter是一款Android路由框架,基于组件化的设计思路,功能灵活,使用也比较简单. WMRouter最初用于解决美团外卖C端App在业务演进过程中的实际问题,之后逐步推广到了美团其他App ...

  9. Java double 精度

    1. 范围  float和double的范围是由指数的位数来决定的.  float的指数位有8位,而double的指数位有11位,分布如下:  float:  1bit(符号位) 8bits(指数位) ...

  10. 【转】让你10分钟搞定Mac--最简单快速的虚拟安装

    文章出处:让你10分钟搞定Mac--最简单快速的虚拟安装http://bbs.itheima.com/thread-106643-1-1.html (出处: 黑马程序员训练营论坛) 首先说明一下. 第 ...