0

I set flagfile like this:

DECLARE_string(flagfile);
int main(int argc, char** argv) {
  FLAGS_flagfile = "./conf/default.conf"
  ParseCommandLineFlags(&argc, &argv, true);
  ....
}

then change flagfile by command line

./main --flagfile=./conf/another.conf

but flagfile is still ./conf/default.conf

How to set flagfile's default value and also accept changes by command line?

Dada
  • 6,313
  • 7
  • 24
  • 43
qincpp
  • 3
  • 2

2 Answers2

0

You can simply check the parameters yourself before calling the ParseCommandLineFlags function.

For example something like:

std::regex flag_regex("--flagfile=(.+.conf)")
std::smatch reg_match;
if(std::regex_match(std::string(argv[1]), reg_match, flag_regex){
   FLAGS_flagfile = reg_match[0];
}

That way you will use the other configuration file. You can change the regex to match differently depending on what you need.

meneldal
  • 1,717
  • 1
  • 21
  • 30
0

Use

google::SetCommandLineOption("flagfile", "gflags_sample.flags");
Dada
  • 6,313
  • 7
  • 24
  • 43
he shouyong
  • 159
  • 3