Boost logo

Boost Users :

From: Stephen Collyer (scollyer_at_[hidden])
Date: 2008-06-06 12:06:40


Is it possible to have boost::program_options emit a
usage message when an unknown option is supplied ?

I have code which is parsing its options like this:

> void UserAPI::parse_options(const std::vector<std::string>& required_options,
> int argc, char* argv[],
> std::string usage)
> {
> po::store(po::parse_command_line(argc, argv, options_desc_, options_style_), vm_);
> po::notify(vm_);
>
> // count how many required options we have
>
> uint count = 0;
> for (std::vector<std::string>::const_iterator s = required_options.begin();
> s != required_options.end(); ++s)
> {
> count += vm_.count(*s);
> }
>
> // if we have a help option, or we don't have all the required options
> // emit the usage message
>
> if ( vm_.count("help") || count != required_options.size()
> )
> {
> std::cout << usage << std::endl;
> std::cout << options_desc_ << std::endl;
> exit(1);
> }
> }

If I pass an unknown option, it seems to be handled
automagically:

> install/linux/general -orgid ABC -p fred
> unknown option -p

I don't want this - I want to catch it somehow and
emit my usage message, but this seems not to be
documented, AFAICS.

Anyone know how this can be done ?

-- 
Regards
Steve Collyer
Netspinner Ltd

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