boost::program_options

Dear boost list It has been discussed several times already that boost::program_options throws an error if an unknown option is encountered. However, for command line options there is a boolean flag to handle unknown option (presumably?) In program_options/details/cmdline.hpp : cmdline(int argc, const char*const * argv, int style, bool allow_unregistered = false); However, common_command_line_parser::run(), when constructing a cmdline object does not forward this flag. I suggest that you change the signature of the run() method to forward that flag, and modify the code section in program_options/src/parsers.cpp current version: parsed_options common_command_line_parser::run() const { parsed_options result(m_desc); detail::cmdline cmd(m_args, m_style); cmd.set_additional_parser(m_ext); if (m_desc) { set<string> keys = m_desc->primary_keys(); for (set<string>::iterator i = keys.begin(); i != keys.end (); ++i) { const option_description& d = m_desc->find(*i); char s = d.short_name().empty() ? '\0' : d.short_name ()[0]; ........... new suggestion: parsed_options common_command_line_parser::run(bool allow_unregistered) const { parsed_options result(m_desc); detail::cmdline cmd(m_args, m_style, allow_unregistered); cmd.set_additional_parser(m_ext); if (m_desc) { set<string> keys = m_desc->primary_keys(); for (set<string>::iterator i = keys.begin(); i != keys.end (); ++i) { const option_description& d = m_desc->find(*i); char s = d.short_name().empty() ? '\0' : d.short_name ()[0]; ........... Does this allow then parsing cmd line option strings which contain unknown options without throwing exceptions? Comment very welcome. Freundliche Grüsse Daniel Egloff Zürcher Kantonalbank, VFEF Josefstrasse 222, 8005 Zürich Tel. +41 (0) 44 292 45 33, Fax +41 (0) 44 292 45 93 Briefadresse: Postfach, 8010 Zürich, http://www.zkb.ch ___________________________________________________________________ Disclaimer: Diese Mitteilung ist nur fuer die Empfaengerin / den Empfaenger bestimmt. Fuer den Fall, dass sie von nichtberechtigten Personen empfangen wird, bitten wir diese hoeflich, die Mitteilung an die ZKB zurueckzusenden und anschliessend die Mitteilung mit allen Anhaengen sowie allfaellige Kopien zu vernichten bzw. zu loeschen. Der Gebrauch der Information ist verboten. This message is intended only for the named recipient and may contain confidential or privileged information. If you have received it in error, please advise the sender by return e-mail and delete this message and any attachments. Any unauthorised use or dissemination of this information is strictly prohibited.

daniel.egloff@zkb.ch wrote: [Doug, there's a question to you as release manager at the end of this emal]
Dear boost list
It has been discussed several times already that boost::program_options throws an error if an unknown option is encountered. However, for command line options there is a boolean flag to handle unknown option (presumably?)
In program_options/details/cmdline.hpp :
cmdline(int argc, const char*const * argv, int style, bool allow_unregistered = false);
However, common_command_line_parser::run(), when constructing a cmdline object does not forward this flag.
Hi Daniel, I have both good news and bad news. The good news is that it's now possible to specify this flag via the public interface. Just command_line_parser(argc, avgv).allow_unregistered().run() will do. The bad news is that my recent refactoring broke support for 'allow_unregistered' inside command line parser. Really bad, especially given that I intended to add 'allow_unregistered' to the public interface as I did the changes. And we're in feature freeze mode now :-( Doug, what's your opinion about my fixing the problem, despite feature freeze? Basically, there's public interface function that does not work at all, so it can be considered as bugfix, not as a new feature. - Volodya

Am Tue, 26 Apr 2005 17:38:52 +0400 schrieb Vladimir Prus:
daniel.egloff@zkb.ch wrote:
[Doug, there's a question to you as release manager at the end of this emal]
Dear boost list
It has been discussed several times already that boost::program_options throws an error if an unknown option is encountered. However, for command line options there is a boolean flag to handle unknown option (presumably?)
In program_options/details/cmdline.hpp :
cmdline(int argc, const char*const * argv, int style, bool allow_unregistered = false);
However, common_command_line_parser::run(), when constructing a cmdline object does not forward this flag.
Hi Daniel, I have both good news and bad news.
The good news is that it's now possible to specify this flag via the public interface. Just
command_line_parser(argc, avgv).allow_unregistered().run()
will do. The bad news is that my recent refactoring broke support for 'allow_unregistered' inside command line parser. Really bad, especially given that I intended to add 'allow_unregistered' to the public interface as I did the changes. And we're in feature freeze mode now :-(
Doug, what's your opinion about my fixing the problem, despite feature freeze? Basically, there's public interface function that does not work at all, so it can be considered as bugfix, not as a new feature.
- Volodya
Hi Volodya, is it possible to get a list of unrecognized options. I have to forward this options to another library. Regards, Thomas

Thomas Dilling wrote:
Doug, what's your opinion about my fixing the problem, despite feature freeze? Basically, there's public interface function that does not work at all, so it can be considered as bugfix, not as a new feature.
- Volodya
Hi Volodya, is it possible to get a list of unrecognized options. I have to forward this options to another library.
I'm still waiting for Doug to comment on my committing this feature. What I plan is that the 'option' class will get two additional members. First is 'bool unknown'. So, you'll be able to walk the vector of option and pick option that have this member set to 'true'. The other new member will be 'vector<string> original_tokens;'. The standard parser will set it to the command line tokens parsed to form the option. It can be used to reconstruct back the unrecognized elements of command line. So, if you pass --foo 10 --bar=12 and no options is registered, you'll get vector of three options. 1. "foo", with no value, and "original_tokens" set to "--foo" 2. 10, which will be marked as positional 3. "bar" with value "12", and "original_tokens" set to "--bar=12" All of them will be 'unknown' flag set. So, you can both pass the unrecognized options to another library, or reconstruct the command line for unrecognized options. Will that be OK for you? - Volodya
Regards, Thomas
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Am Fri, 29 Apr 2005 09:55:56 +0400 schrieb Vladimir Prus:
Hi Volodya, is it possible to get a list of unrecognized options. I have to forward this options to another library.
I'm still waiting for Doug to comment on my committing this feature. What I plan is that the 'option' class will get two additional members. First is 'bool unknown'. So, you'll be able to walk the vector of option and pick option that have this member set to 'true'.
The other new member will be 'vector<string> original_tokens;'. The standard parser will set it to the command line tokens parsed to form the option. It can be used to reconstruct back the unrecognized elements of command line.
So, if you pass
--foo 10 --bar=12
and no options is registered, you'll get vector of three options.
1. "foo", with no value, and "original_tokens" set to "--foo" 2. 10, which will be marked as positional 3. "bar" with value "12", and "original_tokens" set to "--bar=12"
All of them will be 'unknown' flag set. So, you can both pass the unrecognized options to another library, or reconstruct the command line for unrecognized options.
Will that be OK for you?
Hi Volodya, sounds great. Better than my idea, which i had last night: optionally passing a std::vector<std::string> in allow_unregistered, in that all unknown options are collected. But doing it this way, options become "neighbors" that were not in the original options list. Regards, Thomas PS: great library, thank you

On Fri, 2005-04-29 at 09:55 +0400, Vladimir Prus wrote:
Thomas Dilling wrote:
All of them will be 'unknown' flag set. So, you can both pass the unrecognized options to another library, or reconstruct the command line for unrecognized options.
Will that be OK for you?
Will this also work for config files? /ikh _______________________________________________________________________ This email has been scanned for all known viruses by the MessageLabs Email Security System. _______________________________________________________________________
participants (4)
-
daniel.egloff@zkb.ch
-
Iain K. Hanson
-
Thomas Dilling
-
Vladimir Prus