gflags 使用GetCommandLineFlagInfo判断flag变量是否已设置
使用GetCommandLineFlagInfo即可例如判断portno是否设置:
#include "bits/stdc++.h"
#include <gflags/gflags.h>
#include "flags.h"
using namespace std;
DEFINE_int32(portno, 0, "portno,默认为0");
int main(int argc, char* argv[])
{
google::SetVersionString("V1.0.0@const.net.cn");
google::SetUsageMessage("-help ");
google::ParseCommandLineFlags(&argc, &argv, true);
google::CommandLineFlagInfo info;
if (GetCommandLineFlagInfo("portno", &info) && info.is_default)
{
std::cout << "portno is not set." << std::endl;
}
else
{
std::cout << "portno is set." << FLAGS_portno <<std::endl;
}
std::cout << FLAGS_string_var<< std::endl;
std::cout << FLAGS_int32_var<< std::endl;
std::cout << FLAGS_bool_var<< std::endl;
return 0;
}
./test_gflags -portno=11
portno is set.11
0
1