|
Boost : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-08-16 02:41:14
Hi Neal,
Neal D. Becker wrote:
> I'm lost with trying to use the (unreleased) program_options lib.
>
> I have no problem to use with just command line, but I'd like to have both
> command line and config file.
>
> Here's what I tried:
>
> try {
> options_description desc("Allowed options");
> desc.add_options()
> ("help", "", "produce help message")
> ("esNodB,e", parameter<double> ("value", &esnodB), "Es/No(dB)")
> ("maxBursts,m", parameter<int> ("value", &maxBursts), "stop after
> #bursts")
> ("maxErrors,M", parameter<int> ("value", &maxErrors), "stop after
> #errors")
> ;
>
> options_and_arguments opts = parse_command_line(argc, argv, desc);
> variables_map vm;
> store(opts, vm, desc);
>
> ifstream ifs("TestUWP.cfg");
> options_and_arguments opts2 = parse_config_file(ifs, desc);
> variables_map cfg_file_vm;
> store(opts2, cfg_file_vm, desc);
>
> vm.next(&cfg_file_vm);
>
> if (vm.count("help")) {
> std::clog << desc << "\n";
> return 1;
> }
>
> }
> catch(std::exception& e) {
> std::cerr << "error: " << e.what() << "\n";
> return 1;
> }
>
> I get this message:
> error: config file options should have required parameter
>
> I tried various variations, and also referred to the multiple_sources
> example,
> but I still can't find out what's wrong. Any clues?
The "help" option has no parameter. The program_options library does not
allow only (name,values) pairs in config file, so it complains about such a
option. One solution is to greate to option_descriptions instances: one for
command line only and one for general parameters. You can then combine
instances for command line parsing and pass only one to config file parser.
Of course, I'm open for other suggestions.
- Volodya
- Volodya
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk