Boost logo

Boost Users :

Subject: [Boost-users] [program options] No value option in config file not allowed.
From: Rodolfo Federico Gamarra (rgamarra_at_[hidden])
Date: 2009-01-25 20:46:38


Hi all!

I'm using parse_config_file to read my options from a file. Some of
them are only a flag (ie no value given), like -z (--gzip), -h
(--help) or -v (--verbose).

What I see is that those options can be specified with the file only
if some dummy value is given. For concreteness, let's say that the
option is gzip. If I put

gzip=

the result is "Error: no value given in 'gzip='". If the = isn't put,
then the message is "Error: unrecognized line in 'gzip'". Using spaces
doesn't help because they are trimmed away.

The method common_config_file_iterator::get() (config_file.cpp) seems
to be involved:

        else if ((n = s.find('=')) != string::npos) {

            string name = m_prefix + trim_ws(s.substr(0, n));
            string value = trim_ws(s.substr(n+1));

            if (!allowed_option(name))
                boost::throw_exception(unknown_option(name));
            //// Doesn't allow empty values for an option.
            if (value.empty())
                boost::throw_exception(invalid_syntax(s, "no value given"));
        
            found = true;
            this->value().string_key = name;
            this->value().value.clear();
            this->value().value.push_back(value);
            break;

        } else {
            boost::throw_exception(invalid_syntax(s, "unrecognized line"));
        }

The trimming may be handy, but it seems useful to allow empty values;
on the other hand, it seems that whether an empty value is legal or
not should be checked on a higher level.

Thanks a lot.

--
Rodolfo Federico Gamarra

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