0

次のようにフラグファイルを設定します。

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

次に、コマンドラインでフラグファイルを変更します

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

しかしflagfileはまだ./conf/default.conf

フラグファイルのデフォルト値を設定し、コマンドラインで変更を受け入れる方法は?

4

2 に答える 2

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.

于 2015-06-19T03:02:28.430 に答える