Boost C++ Libraries: Ticket #6991: Provide a way to disable interspersed arguments https://svn.boost.org/trac10/ticket/6991 <p> I'm trying to write a program that wraps other programs, and allowing switches to come after the first positional argument in this situation is very annoying from the user's standpoint. </p> <p> If I define the flag --flag in my wrapper, it means that </p> <pre class="wiki"> my-program target-program --flag </pre><p> won't run <code>target-program --flag</code> as one would hope, but will treat <code>--flag</code> as an argument to my program. </p> <p> This means that the user has to run <code>my-program -- target-program --flag</code> every time, which is both annoying and goes against how most such programs work on Unix. (You never see someone say "run <code>sudo -- apt-get install blah</code>." Or xargs, env, nohup, etc.) </p> <p> As far as I'm concerned, this problem is a showstopper for using the stock Boost po for this sort of program. If the Gflags library didn't have the same limitation, I'd be using it right now instead of having patched Boost. :-) </p> <p> So I request a setting to disable this sort of interspersed arguments. </p> <hr /> <p> Fortunately, (one possible) fix seems to be pretty simple from what I can tell. I'll follow up this post with a patch after I get things cleaned back up and such. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6991 Trac 1.4.3 driscoll@… Fri, 15 Jun 2012 22:24:27 GMT attachment set https://svn.boost.org/trac10/ticket/6991 https://svn.boost.org/trac10/ticket/6991 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">po.patch</span> </li> </ul> Ticket driscoll@… Fri, 15 Jun 2012 22:25:09 GMT <link>https://svn.boost.org/trac10/ticket/6991#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6991#comment:1</guid> <description> <p> Okay, there's the patch, relative to the current svn trunk (rev78961). I didn't put a ton of effort into figuring out the best way to do it, but it seems to work and be relatively elegant. I also had trouble compiling the example program example/options_description.cpp so it's untested as-is, but it does build for me and basically the same patched seemed to work with 1.49. </p> <p> What I'm <em>not</em> sure about is the best way to add the option to the library instead of hard-coding it. I haven't taken a good enough look to figure out where that should be added. (Maybe the style flags?) </p> <p> I'm willing to help out a little on this, e.g. writing documentation, if it would help get it into a release. :-) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Mateusz Loskot</dc:creator> <pubDate>Fri, 15 Jun 2012 22:54:59 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/6991#comment:2 https://svn.boost.org/trac10/ticket/6991#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">mateusz@…</span> added </li> </ul> <p> I asked it on boost-users, but perhaps it's missed. Is this ticket also related this issue <a class="new ticket" href="https://svn.boost.org/trac10/ticket/5201" title="#5201: Bugs: Negative numbers as options and values not parsed correctly (new)">#5201</a> ? </p> Ticket driscoll@… Mon, 18 Jun 2012 17:24:43 GMT <link>https://svn.boost.org/trac10/ticket/6991#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6991#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6991#comment:2" title="Comment 2">mloskot</a>: </p> <blockquote class="citation"> <p> I asked it on boost-users, but perhaps it's missed. Is this ticket also related this issue <a class="new ticket" href="https://svn.boost.org/trac10/ticket/5201" title="#5201: Bugs: Negative numbers as options and values not parsed correctly (new)">#5201</a> ? </p> </blockquote> <p> I responded by email (assuming I got the address right) but it occurred to me it might be worth posting back here. </p> <p> I thank the answer is "no". Though of course I'm not particularly well-versed in the library implementation. </p> <p> From what I can see, the negative number problem seems to concern when multitoken cuts off its search. I know the code little enough that I'm confused <em>how</em> this happens, but if I use the following option description: </p> <pre class="wiki"> desc.add_options() ("help", "produce help message") ("compression", value&lt;string&gt;(), "compression level") ("verbose", value&lt;string&gt;()-&gt;zero_tokens(), "verbosity level") ("email", value&lt;vector&lt;string&gt; &gt;()-&gt;multitoken(), "email") ; </pre><p> and run </p> <pre class="wiki"> ./example --email a b c --compression d </pre><p> then it gives me a vector of ["a", "b", "c"] for email and a compression of "d". So obviously it's cutting off reading in <code>--email</code> arguments early. </p> <p> My reading of issue 5201 is that something like <code>--foo 1.0 -1.0</code> will cause reading of <code>--foo</code>'s arguments to end when it sees the next "-". </p> <p> (Incidentally this example is modified from the one at <a href="http://www.boost.org/doc/libs/1_49_0/doc/html/program_options/overview.html#id2500805">http://www.boost.org/doc/libs/1_49_0/doc/html/program_options/overview.html#id2500805</a> which has email as a <code>value&lt;string&gt;</code>. That seems wrong though... are the docs wrong there?) </p> <p> (However, my analysis here could be wrong.) </p> <p> My issue is just that when the parser hits the first argument that none of the "style_parsers" recognize, it should stop parsing and treat everything that follows as a positional argument. (This is the same thing that parse_terminator does when it sees a '--' argument on its own, except that the -- gets thrown away. That's why I added the desired behavior at that point in the code.) </p> </description> <category>Ticket</category> </item> <item> <author>driscoll@…</author> <pubDate>Fri, 06 Jul 2012 00:21:00 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/6991 https://svn.boost.org/trac10/ticket/6991 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">po-allow_interspersed.patch</span> </li> </ul> Ticket anonymous Fri, 06 Jul 2012 00:21:21 GMT attachment set https://svn.boost.org/trac10/ticket/6991 https://svn.boost.org/trac10/ticket/6991 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">po-disallow_interspersed.patch</span> </li> </ul> Ticket driscoll@… Fri, 06 Jul 2012 00:23:37 GMT <link>https://svn.boost.org/trac10/ticket/6991#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6991#comment:4</guid> <description> <p> Added two possibilities for a patch that allow the user to choose this behavior it via the style parameter of the basic_command_line_parser. The version with <code>allow_interspersed</code> is more consistent with the library now, but breaks backwards compatibility (see <a class="ext-link" href="http://lists.boost.org/boost-users/2012/07/75101.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2012/07/75101.php</a>). The version with <code>disallow_interspersed</code> should not affect current programs. </p> </description> <category>Ticket</category> </item> <item> <author>driscoll@…</author> <pubDate>Fri, 06 Jul 2012 00:26:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6991#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6991#comment:5</guid> <description> <p> (Patches include a test case. They are relative to svn trunk @ rev 79301.) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 17 Oct 2012 09:09:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6991#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6991#comment:6</guid> <description> <p> I'm sad to see that this patch did not make it into 1.52.0.beta1. Is there any chance of seeing it in 1.52.1? </p> </description> <category>Ticket</category> </item> </channel> </rss>