|
Boost Users : |
Subject: Re: [Boost-users] boost::program_options silent name conflicts
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2010-04-28 19:57:30
On Wed, Apr 28, 2010 at 4:41 PM, Michael Jeung <jeungster_at_[hidden]> wrote:
> Hello all,
>
> I've run into a problem with the boost::program_options library and I
> wanted to see if anyone has experienced something similar.
>
> When my application defines two program options, pi and pie, the "pie"
> option silently overrides the "pi" option. (Source code attached.)
>
> ./my_program --pie
> pi: false
> pie: true
>
> ./my_program --pi
> pi: false
> pie: true
>
> Is this the expected behavior? Â Admittedly, this is a contrived
> example, but I think there are real-life cases where it can cause
> problems. Â I have run into it a couple of times now.
>
> -Michael
>
> -----------------------------------------------------------
>
>
> #include <boost/program_options.hpp>
> #include <iostream>
>
> namespace po = boost::program_options;
>
> int main( const int argc, char *argv[] )
> {
> Â bool pi = false;
> Â bool pie = false;
>
> Â po::options_description desc("Allowed options");
> Â desc.add_options()
> Â Â ("help,h", "produce help message")
> Â Â ("pi", po::value<bool>(&pi)->zero_tokens(), "calculate pi")
> Â Â ("pie", po::value<bool>(&pie)->zero_tokens(), "serve pie to our guests")
> Â Â ;
>
> Â po::variables_map vm;
> Â po::store(po::command_line_parser(argc,
> argv).options(desc).allow_unregistered().run(), vm);
> Â po::notify(vm);
>
> Â if (vm.count("help"))
> Â {
> Â std::cout << desc << std::endl;
> Â return 0;
> Â }
>
> Â if ( pi )
> Â std::cout<<"pi: true"<<std::endl;
> Â else
> Â std::cout<<"pi: false"<<std::endl;
>
> Â if ( pie )
> Â std::cout<<"pie: true"<<std::endl;
> Â else
> Â std::cout<<"pie: false"<<std::endl;
>
> }
That is caused be the ability for you to specify shorter names for the
longer versions on the command line, for some causes (such as yours),
you want to disable it. I do not know the command to do that, but it
was on the mailing list not far back as I recall (probably/hopefully
in the docs too). I cannot look it up at the moment, on my phone.
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