|
Boost Users : |
Subject: [Boost-users] [program options] Constraints, missing options
From: Georg Sauthoff (g_sauthoff_at_[hidden])
Date: 2008-12-18 03:25:51
Hi,
I am using boost.Program_options and it is quite useful. I miss two
features, though. I could not find a way to specify that some option
should be mandatory at the command line. Or that some option has to be
present at least x times and at most y times at the command line.
I mean I can check it myself if the Program_options parser is finished -
but I like it better, if the library would do the work for me.
In pseudocode I want to write something like this for example:
opts.add_options()("file,f", value< vector<string> >()
->min_times(1)->max_times(2), "blah blah");
./a.out -f foo -f bar # ok
./a.out -f foo -f bar -f bas # exception from the Program_options parser
Is this feature missing, or have I overlooked it in the
documentation?
Another thing I couldn't find: a way to switch program options into a
'checking mode'; i.e. a mode, where the program options code throws an
exception if the count of an non existing option is queried (in case of
an programming error).
For example
desc.add_options()
("help,h", "produce help message");
...
vm.set_pedantic(); // <- pseudo code
vm.count("foobar"); // <- would throw exception
Or even better, if it is possible do register some enum value, which can
be used to index into the variables_map - I mean, to get a compile error
the option identifier is misspelled (instead of an runtime error ...):
enum my_opts { HELP };
desc.addoptions()("help,h", HELP, "produce help message");
vm.count(EHLP); // <- compile error ...
Best regards
Georg
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net