Boost logo

Boost Users :

Subject: Re: [Boost-users] [Program Options] terminate parsing after first positional argument
From: driscoll_at_[hidden]
Date: 2012-07-06 01:43:39


> On 06.07.2012 04:25, Evan Driscoll wrote:
>> One more post to this thread for now then I'm done for a bit. :-)
>>
>> I implemented both versions (allow_interspersed and
>> disallow_interspersed) with a test. Patches for each are now up at the
>> issue tracker.
>> https://svn.boost.org/trac/boost/ticket/6991
>
> Evan,
>
> I was thinking about option called allow_interspersed with a default value
> of '1' -- so that you'd have to remove
> it from default style if you don't want it. Does this seem reasonable?

Yes, but I don't see how to get it in a consistent way. (Well, not
*entirely* true: see #4 below.)

When you said "style" in your last email, it reminded me that there's a
style_t enum defined in cmdline.hpp [1]. This enum is of the "define
values with one bit set, so that people can or them together as a bitmask"
variety, and has things like "allow long options" and "use Windows-style
/options" and "-abc is like -a -b -c".

What I thought you were suggesting, and what seems reasonable, was to add
a new style flag for interspersed arguments, with the next bit set.

But the problem is that I can't make it default to 1 if I do that, because
people can | together flags to form their own style and ignore the new
one, and of course then the allow_interspersed bit wouldn't be set. (This
is what the test cases do.) If someone says
  style_t style = allow_short | allow_slash_for_short
I can't automatically go and set allow_interspersed for them as well.

This means that, unless I'm missing something, it seems like we have these
options (#2 is my favorite):

1. Do it anyway and break compatibility (probably only bad for a very very
small number of people -- but it will be *very* bad for them)

2. Implement the reverse flag, disallow_interspersed, which works out fine
but is opposite all the other style_t flags (not great but not awful)

3. Implement this via a different mechanism. There *is* a bit of
precedence for this with the parser's allow_unregistered() function [2],
which sets a flag in the parser somewhere and eventually it works its way
down where it's checked from the cmdline::finish_option function [3].

However, we still have to decide on the API. It shouldn't just be
cmdline::allow_interspersed() like allow_unregistered(), because
interspersed arguments will already be allowed. So it could either take a
boolean, and then I'd call it like 'command_line_parser(argc,
argv).allow_interspersed(false).run()', or we could call it
disabled_interspersed().

(A reasonable choice but even more inconsistent with the other style
options than #2 was, and I like that one more. allow_interspersed has more
in common with the other style_t flags than it does with
allow_unregistered(), and the new API wouldn't even exactly mirror
allow_unregistered() anyway unless that were changed as well.)

4. (The "a bit of work" choice.) Stop using an enum. Create (or use?) a
class that well let you | together individual values like people are doing
now, but which will start with the allow_interspersed option set (because
now we get a constructor).

(This would be a fair bit of work, probably a little error-prone, and to
provide full-backwards compatibility would probably have to provide
conversions from 'int' and other ugly stuff like that. In some ways it's
the nicest option, but I'm still not in favor.)

5. (Ugly hack.) Redefine all the other style options so that the
allow_interspersed bit is set as well. E.g. 'allow_long = 1 |
allow_interspersed'.

(This is offensively bad and I'm kind of ashamed I even thought of it. But
it is *technically* an option.)

[1] http://www.boost.org/doc/libs/1_50_0/boost/program_options/cmdline.hpp
[2]
http://www.boost.org/doc/libs/1_50_0/doc/html/program_options/howto.html#id2523046
[3]
http://svn.boost.org/svn/boost/trunk/libs/program_options/src/cmdline.cpp
about 2/3 of the way down

Evan


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