Boost logo

Boost Users :

Subject: Re: [Boost-users] program options: unrecognized command-line options
From: Deane Yang (deane.yang_at_[hidden])
Date: 2009-01-15 08:26:04


Peter Bartlett wrote:
> Quoting Deane Yang <deane.yang_at_[hidden]>:
>
>> Christoph Duelli wrote:
>>> Deane Yang wrote:
>>>
>>>> I'm using the program options library to parse both command-line and
>>>> configuration file parameters. I'd like to know how to find
>>>> command-line
>>>> arguments that are *not* registered and therefore not recognized by the
>>>> parser. I want to be able to print a warning message like "Following
>>>> arguments were ignored:....".
>>>
>>> I did it like that:
>>>
>>> // assume that options is a std::vector<std::string> containing
>>> // the passed options (argv[])
>>> po::options_description desc; // contains the options your prog supports
>>>
>>>
>>> po::variables_map vm;
>>> po::command_line_parser
>>> parser(options).allow_unregistered().options(desc);
>>>
>>> po::parsed_options parsed = parser.run();
>>> po::store(parsed, vm);
>>> po::notify(vm); // recognized options
>>>
>>> std::vector<std::string> unrecognizedOptions =
>>> po::collect_unrecognized(parsed.options, po::include_positional);
>>>
>>>
>>> This is documented at
>>> doc/html/program_options/howto.html#id3458178 in your Boost docs.
>>>
>>
>> Thanks. I did see this, but was hoping for something more graceful. I
>> find it ironic that to disallow unregistered options, I have to use the
>> function allow_unregistered. Shouldn't the opposite of
>> "allow_unregistered" be a state where unregistered options are
>> forbidden?
>
> That's perhaps a little unfair as the library by default throws an
> exception on discovering unregistered options. Is it the case that you
> are just looking for a better exception message?

Agreed. So I apologize. For some reason I did not see this happening
before. I was under the impression that the unregistered options were
simply being ignored.


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