Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2006-04-24 05:16:26


Alexander Kondratyuk wrote:

> Have a problem with using additional parser feature:
> I want to allow user to use double dashes for short options, so user will
> use "-h" or "--h".
> But using additional parser the code throws an error about syntax. It
> seems there is a bug in additional parser wrapper - in case then my option
> has no parameters defined and declared in description it adds an empty
> value to the vector of values when additional paser returns pair of
> strings.
>
> Perhaps there is another way to get what I want, please let me know how to
> do it?

I think you're better of using new 'style_parser' interface, which is
similar in idea but is a bit more flexible. Here's relevant bits of code:

std::vector<option> parseDashDashShort(std::vector<std::string>& cmdline)
{
    std::vector<option> result;
    string s = cmdline[0];
    string str = s.substr( 0, s.find('=') );
    if( str.length()==3 && str[0]=='-' && str[1]=='-' && str[2]<='z' &&
        str[2]>='a')
    {
        result.push_back(option(str.substr(1), std::vector<string>()));
        cmdline.erase(cmdline.begin());
    }
    return result;
}

....
 command_line_parser(argc, (char**)args).options(desc).style(style)
        .extra_style_parser(parseDashDashShort).run();

I've just modified the logic so that empty second element of return value
from from additional parser is considered to mean no value, but using empty
string to mean 'nothing' is still a bit dirty, so I suggest you consider
using the new interface.

- Volodya


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