#include <gflags/gflags.h>
DEFINE_bool(big_menu, true, "Include ‘advanced‘ options in the menu listing");
DEFINE_string(languages, "english,french,german", "comma-separated list of languages to offer in the ‘lang‘ menu");
int main(int argc, char **argv) {
google::ParseCommandLineFlags(&argc, &argv, true);
cout << "argc=" << argc << endl;
if (FLAGS_big_menu) {
cout << "big menu is ture" << endl;
} else {
cout << "big menu is flase" << endl;
}
cout << "languages=" << FLAGS_languages << endl;
return 0;
}
运行程序
直接运行
run
1
2
3
4
? bin ./sample
argc=1
big menu is ture
languages=english,french,german
? bin ./sample --help
sample: Warning: SetUsageMessage() never called
Flags from /home/shougang/workspace/drive/Google/cmake_cpp_gflags/src/sample.cc:
-big_menu (Include ‘advanced‘ options in the menu listing) type: bool
default: true
-languages (comma-separated list of languages to offer in the ‘lang‘ menu)
type: string default: "english,french,german"
Flags from src/gflags.cc:
-flagfile (load flags from file) type: string default: ""
.........
? bin ./sample --helpshort
sample: Warning: SetUsageMessage() never called
Flags from /home/shougang/workspace/drive/Google/cmake_cpp_gflags/src/sample.cc:
-big_menu (Include ‘advanced‘ options in the menu listing) type: bool
default: true
-languages (comma-separated list of languages to offer in the ‘lang‘ menu)
type: string default: "english,french,german"
DEFINE_bool(big_menu, true, "Include ‘advanced‘ options in the menu listing");
DEFINE_string(languages, "english,french,german", "comma-separated list of languages to offer in the ‘lang‘ menu");