#3751 closed Feature Requests (fixed)
I suggest to substitute "multiple_sources.cpp" on an offered variant.
Reported by: | Owned by: | Vladimir Prus | |
---|---|---|---|
Milestone: | Boost 1.42.0 | Component: | program_options |
Version: | Boost 1.41.0 | Severity: | Cosmetic |
Keywords: | Cc: |
Description
The offered variant shows possibility of the assign in the command line of a filename of a configuration.
Attachments (2)
Change History (13)
by , 13 years ago
Attachment: | multiple_sources.cpp added |
---|
comment:1 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 13 years ago
Thanks for enhancement.
I did some small modifications (removed tabs, converted via dos2unix ...). There was also one problem: The value from command line is stored in config_file only after notify() call. I fixed that.
comment:3 by , 13 years ago
Excuse, but this example has entered in contradicted with new (very useful) property "required". After the first call "notify (vm)" the exception for the options which values are set in the configuration file will be generated. How to be now I do not know. Probably to enter new function for stock-taking of all demanded options.
comment:4 by , 13 years ago
Hm, I'm not sure of what you're talking about? What exception do you mean? What do you try?
Thanks, Sascha
comment:5 by , 13 years ago
if lines 47-48: "("optimization", po::value<int>(&opt)->default_value(10),"optimization level")" change to: "("optimization", po::value<int>(&opt)->required(),"optimization level")" and exec: multiple_sources.exe there will be an exception in lines 77 (first "notify(vm);").
comment:6 by , 13 years ago
Yes, the "required" check is done in notify().
You can try not to store in existing variables and then remove the first notify() call:
("optimization", po::value<int>()->default_value(10),"optimization level")
I'm going to check why values for existing variables are applied in notify() ...
comment:9 by , 13 years ago
Hm, I can not reproduce, debugger shows that config_file is set correctly after the following line:
string config_file = vm["config"].as< string >();
(default if not given on command line, otherwise set to value given on command line. I use current trunk version
comment:10 by , 13 years ago
Excuse. I did not set parametre in the command line, therefore and received "defaulted ()".
(In [58289]) Enhance example, Fixes #3751, Patch from Alex Bukreev