关于学习
gflags code
在细节上,我发现了一个API
gflags::GetCommandLineFlagInfoOrDie(const char* name)
哪些回报
CommandLineFlagInfo
,其中包含一个名为
is_defaul
如果在命令行中提供了标志,则为假:
struct CommandLineFlagInfo {
std::string name; // the name of the flag
//...
bool is_default; // true if the flag has the default value and
// has not been set explicitly from the cmdline
// or via SetCommandLineOption
//...
};
所以我不再需要黑客了:
DEFINE_string("output_dir", ".", "existing directory to dump output");
static bool flag_set = false;
int main(int argc, char** argv) {
CheckFlags(argc, argv);
gflags::ParseCommandLineFlags(argc, argv, true);
bool flag_not_set = gflags::GetCommandLineFlagInfoOrDie("output_dir").is_default;
if (!flag_not_set) {
// blah.. blah..
}
return 0;
}