1

I am trying to get input options using boost::program_options.

I would like to have two source of options one from command line and another from file but I also want to have different option names for the same value.

commandLine.add_options()
 ("dim,d", po::value<int>(&dimension), "Problem dimension")
 ("adv", po::value<bool>(&adv_enabled), "Enable/Disable advection term {1|0}")
 ("div", po::value<bool>(&div_enabled), "Enable/Disable divergance term {1|0}")

file_options.add_options()
 ("dimension",po::value<int>(&dimension), "Set Problem dimension")
 ("enable.advection", po::value<bool>(&adv_enabled), "Enable/Disable advection")
 ("enable.divergance", po::value<bool>(&div_enabled), "Enable/Disable divergance")

Here I want to use shorter versions in command line and grouped versions in file.

Is there a way to just pass the variable to both or should I parse them in code?

vbence
  • 20,084
  • 9
  • 69
  • 118
Ashkan
  • 1,050
  • 15
  • 32
  • Looks like command line options values will be overwritten by file option values. Is that what you want? Did you try executing? – HAL Feb 20 '14 at 14:22
  • I want to overwrite file options with command line options but it is not doing what I want. I test run the code and if I change say dimension with command line, it will not update the value. – Ashkan Feb 21 '14 at 15:49

1 Answers1

0

The answer is quite straightforward in the documentation:

Of course, there will be a need to combine the values from command line and config file. For example, the optimization level specified on the command line should override the value from the config file. On the other hand, include paths should be combined.

... what happens if the same value is specified both on the command line and in config file? Usually, the value stored first is preferred. This is what happens for the "--optimization" option. For "composing" options, like "include-file", the values are merged.
http://www.boost.org/doc/libs/1_55_0/doc/html/program_options/tutorial.html#idp163316264

You can add options which repeat on the command line and in the config, and if it is a non-merging option, the preference will be given to the one first called with po::store()

mockinterface
  • 14,452
  • 5
  • 28
  • 49