Boost logo

Boost :

From: daniel.egloff_at_[hidden]
Date: 2005-04-26 07:18:24


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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk