boost::program options question. Implicit() doesn't seem to work
Hi, I was playing around with the boost::program_options class... According to the documentation the line: desc.add_options() ("debug", po::valuestd::string()->implicit(), "enable debugging" ); enables me to do something like this: myexec --debug However, if I do that I get an assertion error. The code requires a string so this will work: myexec --debug whatever What am I doing wrong? Is it me or is it the library? I'm using Visual C++ 2005 Express Beta, WinXP Pro Service Pack2. Thanks, Alexis Below my test program: namespace po = boost::program_options; int main (int argc, char **argv) { po::options_description desc("Allowed ptions"); desc.add_options() ("help", "produce help message") ("compression", po::value<int>(), "set compression level") ("debug", po::valuestd::string()->implicit() ,"enable debugging" ) ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc),vm); po::notify(vm); if (argc==1 || vm.count("help")) { std::cout << desc << "\n"; return 1; } if (vm.count("compression")) std::cout << vm["compression"].as<int>() << std::endl; if (vm.count("debug")) std::cout << vm["debug"].asstd::string() << std::endl; if (vm.count("log-file")) std::cout << vm["compression"].asstd::string() << std::endl; } (By the way, the section Syntactic information of the documentation is not accurate when it says I could do this: desc.add_options() ("compression", "compression level",value<string>()) ("verbose", "verbosity level",value<string>()->implicit()) ("email", "email to send to",value<string>()->multitoken()); That doesn't compile. If I put the second string as the last argument it works.) Programming Tutorial: In Python: To do this, do this In Perl: To do this, do this or this or this or this... In C: To do this, do this, but be careful In C++: To do this, do this, but don't do this, be careful of this, watch out for this, and whatever you do, don't do this __________________________________ Celebrate Yahoo!'s 10th Birthday! Yahoo! Netrospective: 100 Moments of the Web http://birthday.yahoo.com/netrospective/
Alexis H. Rivera-Rios wrote:
According to the documentation the line: desc.add_options() ("debug", po::valuestd::string()->implicit(), "enable debugging" );
enables me to do something like this: myexec --debug
However, if I do that I get an assertion error. The code requires a string so this will work: myexec --debug whatever
What am I doing wrong? Is it me or is it the library?
I think it's the library. But in any case, I plan to remove the 'implicit' flag in 1.33. Why do you want it? What about: desc.add_options() ("debug", bool_option(), "enable debugging") ? - Volodya
On Wed, 09 Mar 2005 10:41:39 +0300, Vladimir Prus
I think it's the library. But in any case, I plan to remove the 'implicit' flag in 1.33. Why do you want it? What about:
Really? I thought that was quite useful for things like. $ foo --help usage: foo [-sexy-options] $ foo --help topic The "topic" option crazumps the doobryferk. Is there a better way than implicit for that? Is implicit causing some ugliness that warrants it's excise?
desc.add_options() ("debug", bool_option(), "enable debugging")
? - Volodya
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Blue Skies
The Grumpiest Man You Know wrote:
On Wed, 09 Mar 2005 10:41:39 +0300, Vladimir Prus
wrote: I think it's the library. But in any case, I plan to remove the 'implicit' flag in 1.33. Why do you want it? What about:
Really? I thought that was quite useful for things like.
$ foo --help usage: foo [-sexy-options] $ foo --help topic The "topic" option crazumps the doobryferk.
Is there a better way than implicit for that?
You can treat 'topic' as positional option and print help for all positional
options when --help is specified. Say:
$ foo surprise
Is implicit causing some ugliness that warrants it's excise?
Yes, because in the above case it's not clear if "topic" is a positional option or value of the "--help" option. I bring this issue in http://article.gmane.org/gmane.comp.lib.boost.devel/118670 - Volodya
participants (3)
-
Alexis H. Rivera-Rios
-
The Grumpiest Man You Know
-
Vladimir Prus