Boost C++ Libraries: Ticket #2727: program_options ill behaviour with unrecognized options https://svn.boost.org/trac10/ticket/2727 <p> Hi! </p> <p> There is an inconsistency in the handling of unrecognized tokens when parsing config-files. The function collect_unrecognized will never return the unknown options, since it just copies of the original_token field which is left empty from the config file parser in contrast to the cmd line parser. </p> <p> Greetings, </p> <p> Sebastian Weber </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2727 Trac 1.4.3 Diederick C. Niehorster <dcnieho@…> Wed, 15 Jul 2009 02:10:55 GMT cc set https://svn.boost.org/trac10/ticket/2727#comment:1 https://svn.boost.org/trac10/ticket/2727#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">dcnieho@…</span> added </li> </ul> <p> Yeah, there must be a cool reason why the original_token field is outputted as the unrecognized options, but i think instead we could simply output the string_key, which is set for all (registered and unregistered) options. if mode == include_positional &amp;&amp; options[i].position_key != -1, add the value for that entry to the output vector. That should do the trick. </p> <p> proposed diff: </p> <pre class="wiki">Index: parsers.hpp =================================================================== --- parsers.hpp (revision 54915) +++ parsers.hpp (working copy) @@ -129,13 +129,12 @@ std::vector&lt; std::basic_string&lt;charT&gt; &gt; result; for(unsigned i = 0; i &lt; options.size(); ++i) { - if (options[i].unregistered || - (mode == include_positional &amp;&amp; options[i].position_key != -1)) - { - copy(options[i].original_tokens.begin(), - options[i].original_tokens.end(), + if (options[i].unregistered) + result.push_back(options[i].string_key); + else if (mode == include_positional &amp;&amp; options[i].position_key != - 1) + copy(options[i].value.begin(), + options[i].value.end(), back_inserter(result)); - } } return result; } </pre> Ticket Sascha Ochsenknecht Tue, 08 Dec 2009 07:40:59 GMT owner, status, milestone changed https://svn.boost.org/trac10/ticket/2727#comment:2 https://svn.boost.org/trac10/ticket/2727#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Vladimir Prus</span> to <span class="trac-author">Sascha Ochsenknecht</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.38.0</span> → <span class="trac-field-new">Boost 1.42.0</span> </li> </ul> <p> The 'cool' reason is that original_tokens are original :-), i.e. they are stored untouched like they appeared on cmdline/config file. The purpose of collect_unrecognized() is to return them and the user can pass them to an own parser implementation. </p> Ticket Sascha Ochsenknecht Tue, 08 Dec 2009 07:45:46 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2727#comment:3 https://svn.boost.org/trac10/ticket/2727#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/58233" title="config file parser now stores original_tokens, Fixes #2727">[58233]</a>) config file parser now stores original_tokens, Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2727" title="#2727: Bugs: program_options ill behaviour with unrecognized options (closed: fixed)">#2727</a> </p> Ticket Sascha Ochsenknecht Tue, 08 Dec 2009 07:48:17 GMT <link>https://svn.boost.org/trac10/ticket/2727#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2727#comment:4</guid> <description> <p> I just checked it a patch which uses a different approach than the above proposal. I decided to store the original_tokens when parsing the config file and keep the collect function untouched. </p> </description> <category>Ticket</category> </item> </channel> </rss>