Boost C++ Libraries: Ticket #469: multitoken broken https://svn.boost.org/trac10/ticket/469 <pre class="wiki">Due to the changes in the parser, multitoken is broken in program_options [boost 1.33]. Looking at the code it is relatively clear why - the parser is too "greedy" and eats up all the options following the multitoken one without checking when to stop (for example, it should stop once it encounters another option/switch). If this functionality is to be deprecated as hinted in some mails on the mailing list, it should be removed from the public interface. If not, I guess it should be fixed :) The way to test it is to have a multitoken switch appear _in the middle_ of the command line (definitely not at the end) which should then simply eat all options to the right of it. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/469 Trac 1.4.3 nobody Mon, 19 Mar 2007 20:48:18 GMT <link>https://svn.boost.org/trac10/ticket/469#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/469#comment:1</guid> <description> <pre class="wiki">Logged In: NO I have encounter the same problems. I need input multiple multitoken. The program options 1.33 does not work in the mutitoken, if it use in the middle of command line. Does anyone have fixed this bug? </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Wed, 11 Jul 2007 18:37:13 GMT</pubDate> <title>summary changed; severity, milestone set https://svn.boost.org/trac10/ticket/469#comment:2 https://svn.boost.org/trac10/ticket/469#comment:2 <ul> <li><strong>summary</strong> <span class="trac-field-old">multitoken broken in program_options 1.33</span> → <span class="trac-field-new">multitoken broken</span> </li> <li><strong>severity</strong> → <span class="trac-field-new">Problem</span> </li> <li><strong>milestone</strong> → <span class="trac-field-new">Boost 1.35.0</span> </li> </ul> <p> Confirmed as a problem. The solution to be decided. </p> Ticket anonymous Thu, 26 Jul 2007 21:01:14 GMT <link>https://svn.boost.org/trac10/ticket/469#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/469#comment:3</guid> <description> <p> Given the following program_options description: </p> <pre class="wiki">std::vector&lt;std::string&gt; multiItems; program_description desc; desc.add_options() ("multi", value&lt;&gt;(&amp;multiItems)-&gt;multitoken(), "..."); .... </pre><p> Would we expect the command line: "myProgram --multi foo bar" to add two entries (foo and bar) into 'multiItems'? </p> <p> It currently (1.34) doesn't; bar gets lost. I can understand that this could be tricky, especially if positional options are also being used. </p> <p> If multitoken was never designed for this purpose, then currently the way to achieve the desired effect is to overload 'validate'. However, this is only necessary because of the use of 'lexical_cast' in the current validate implementations. </p> <p> To illustrate: </p> <pre class="wiki">typedef std::pair&lt;int int&gt; PairOfInts; PairOfInts pairOfInts; program_description desc; desc.add_options() ("pair", value&lt;&gt;(&amp;pairOfInts), "..."); .... </pre><p> With command line: "myProgram --pair 1 2": </p> <p> The current 'validate' code will stream (via lexical_cast) the string "1 2" into lexical_stream, then stream it out to the value type, i.e. the std::pair. </p> <p> The problem there is that the stream-out of the string will only take the "1" part, so when it attempts to stream it back in, only one value is presented. </p> <p> If we had provided a stream operator for our pair: </p> <pre class="wiki">std::istream&amp; operator&gt;&gt;(std::istream &amp;a_istr, PairOfInts &amp;a_pair) { a_istr &gt;&gt; a_pair.first &gt;&gt; a_pair.second; return a_istr; } </pre><p> Then an exception would fire trying to get the second value. </p> <p> The 'validate' code has a vector of strings, but only the first entry is filled. </p> <p> If the current (detail/value_semantic.hpp) validate code: </p> <pre class="wiki">template&lt;class T, class charT&gt; void validate(boost::any&amp; v, const std::vector&lt; std::basic_string&lt;charT&gt; &gt;&amp; xs, T*, long) { validators::check_first_occurrence(v); std::basic_string&lt;charT&gt; s(validators::get_single_string(xs)); try { v = any(lexical_cast&lt;T&gt;(s)); } catch(const bad_lexical_cast&amp;) { boost::throw_exception(invalid_option_value(s)); } } </pre><p> Was adjusted to not use lexical_cast, e.g.: </p> <pre class="wiki">template&lt;class T, class charT&gt; void validate(boost::any&amp; v, const std::vector&lt; std::basic_string&lt;charT&gt; &gt;&amp; xs, T*, long) { validators::check_first_occurrence(v); std::basic_string&lt;charT&gt; s(validators::get_single_string(xs)); std::istringstream istr(s); T value; if (!(istr &gt;&gt; value) { boost::throw_exception(invalid_option_value(s)); } v = value; } </pre><p> Then more complex types could be supported just by providing the stream-in operator, rather than overloaded 'validate's (that seem to have to go in namespace boost, too). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 12 Mar 2009 13:34:00 GMT</pubDate> <title>status, version, component, severity, milestone changed https://svn.boost.org/trac10/ticket/469#comment:4 https://svn.boost.org/trac10/ticket/469#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">new</span> </li> <li><strong>version</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">Boost 1.38.0</span> </li> <li><strong>component</strong> <span class="trac-field-old">config</span> → <span class="trac-field-new">program_options</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Showstopper</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> This multitoken bug has been broken and reported as a bug for 4 years now and not addressed. Is the author/supported not planning on ever fixing it? I'm stuck on boost 1.32 just because of this one bug. </p> Ticket Vladimir Prus Fri, 03 Apr 2009 13:42:33 GMT status, resolution changed https://svn.boost.org/trac10/ticket/469#comment:5 https://svn.boost.org/trac10/ticket/469#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/52154" title="When processing value multitoken options, don't eat futher options. ...">[52154]</a>) When processing value multitoken options, don't eat futher options. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/469" title="#469: Bugs: multitoken broken (closed: fixed)">#469</a>. </p> Ticket Vladimir Prus Mon, 06 Apr 2009 09:36:27 GMT <link>https://svn.boost.org/trac10/ticket/469#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/469#comment:6</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/52210" title="Merge from release: When processing value multitoken options, don't ...">[52210]</a>) Merge from release: When processing value multitoken options, don't eat futher options. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/469" title="#469: Bugs: multitoken broken (closed: fixed)">#469</a>. </p> </description> <category>Ticket</category> </item> </channel> </rss>