Boost C++ Libraries: Ticket #545: Program_options: Fails to parse options with a common root https://svn.boost.org/trac10/ticket/545 <pre class="wiki">Given the following testcase: #include &lt;iostream&gt; #include &lt;boost/program_options.hpp&gt; namespace opt = boost::program_options; int main(int argc, char *argv[]) { try { bool all, all_chroots, all_sessions; opt::options_description chroot("Chroot selection"); chroot.add_options() ("all,a", "Select all chroots and active sessions") ("all-chroots", "Select all chroots") ("all-sessions", "Select all active sessions"); opt::variables_map vm; opt::store(opt::parse_command_line(argc, argv, chroot), vm); opt::notify(vm); if (vm.count("all")) all = true; if (vm.count("all-chroots")) all_chroots = true; if (vm.count("all-sessions")) all_sessions = true; return 0; } catch (std::exception const&amp; e) { std::cerr &lt;&lt; e.what() &lt;&lt; std::endl; return 1; } } $ g++ -o opt opt.cc -lboost_program_options $ ./opt --help unknown option help $ ./opt --all-chroots $ ./opt --all-sessions $ ./opt --all ambiguous option all --all is not abiguous, since it's an exact match. It's not ambigous for GNU getopt or GLib GOption, so this is IMHO a bug. Regards, Roger ii libboost-dev 1.33.0-6 Boost C++ Libraries development fi ii libboost-program-options1.33. 1.33.0-6 program options library for C++ </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/545 Trac 1.4.3 Vladimir Prus Mon, 09 Jan 2006 09:09:27 GMT status changed https://svn.boost.org/trac10/ticket/545#comment:1 https://svn.boost.org/trac10/ticket/545#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> <pre class="wiki">Logged In: YES user_id=321498 A fix and a test were just committed. Thanks for the report! </pre> Ticket christian.blichmann@… Tue, 22 Jun 2010 13:10:36 GMT attachment set https://svn.boost.org/trac10/ticket/545 https://svn.boost.org/trac10/ticket/545 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">program_options.patch</span> </li> </ul> <p> Patch for parsing options with same name-prefix </p> Ticket christian.blichmann@… Tue, 22 Jun 2010 13:11:22 GMT severity set https://svn.boost.org/trac10/ticket/545#comment:2 https://svn.boost.org/trac10/ticket/545#comment:2 <ul> <li><strong>severity</strong> → <span class="trac-field-new">Problem</span> </li> </ul> <blockquote> <p> As of Boost 1.43.0 this is still problematic, see the test case below: </p> </blockquote> <p> </p> <blockquote> <p> #include &lt;iostream&gt; #include &lt;boost/program_options.hpp&gt; namespace po = boost::program_options; </p> </blockquote> <p> </p> <blockquote> <p> int main(int argc, char *argv[]) { </p> <blockquote> <p> try { </p> <blockquote> <p> bool all, all_chroots, all_sessions; </p> </blockquote> </blockquote> </blockquote> <p> </p> <blockquote> <blockquote> <blockquote> <p> po::options_description chroot("Chroot selection"); chroot.add_options() </p> <blockquote> <p> ("flag", "Some boolean flag") ("flag2", "Another flag that gets matched approximately"); </p> </blockquote> </blockquote> </blockquote> </blockquote> <p> </p> <blockquote> <blockquote> <blockquote> <p> po::variables_map vm; po::store(po::parse_command_line(argc, argv, chroot), vm); po::notify(vm); </p> </blockquote> </blockquote> </blockquote> <p> </p> <blockquote> <blockquote> <blockquote> <p> std::cout &lt;&lt; "flag: " &lt;&lt; vm.count("flag") &lt;&lt; std::endl; std::cout &lt;&lt; "flag2: " &lt;&lt; vm.count("flag2") &lt;&lt; std::endl; </p> </blockquote> </blockquote> </blockquote> <p> </p> <blockquote> <blockquote> <blockquote> <p> return 0; </p> </blockquote> <p> } catch (std::exception const&amp; e) { </p> <blockquote> <p> std::cerr &lt;&lt; e.what() &lt;&lt; std::endl; return 1; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> </p> <blockquote> <p> Results: </p> </blockquote> <p> </p> <blockquote> <p> $ g++ -o po-test po-test.cpp -lboost_program_options $ ./po-test --flag flag: 0 flag2: 1 $ ./po-test --flag2 flag: 0 flag2: 1 $ ./po-test --flag --flag2 multiple occurrences </p> </blockquote> <p> </p> <blockquote> <p> Expected results (after applying program_options.patch): </p> </blockquote> <p> </p> <blockquote> <p> $ ./po-test --flag flag: 1 flag2: 0 $ ./po-test --flag2 flag: 0 flag2: 1 $ ./po-test --flag --flag2 flag: 1 flag2: 1 </p> </blockquote> Ticket christian.blichmann@… Tue, 22 Jun 2010 13:13:53 GMT status, component, summary, version changed; milestone set; resolution deleted https://svn.boost.org/trac10/ticket/545#comment:3 https://svn.boost.org/trac10/ticket/545#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">program_options</span> </li> <li><strong>summary</strong> <span class="trac-field-old">Proogram_options: Fails to parse options with a common root</span> → <span class="trac-field-new">Program_options: Fails to parse options with a common root</span> </li> <li><strong>version</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">Boost Development Trunk</span> </li> <li><strong>milestone</strong> → <span class="trac-field-new">Boost 1.44.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">Fixed</span> </li> </ul> Ticket Vladimir Prus Tue, 22 Jun 2010 15:54:41 GMT <link>https://svn.boost.org/trac10/ticket/545#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/545#comment:4</guid> <description> <p> You have set 'version' to 'Boost Development Trunk'. Have you actually tried with trunk? I guess not, since trunk appears to give your expected results on your testcase. Could you please double-check with trunk, and then mark this issue fixed again? </p> </description> <category>Ticket</category> </item> <item> <author>christian.blichmann@…</author> <pubDate>Thu, 24 Jun 2010 07:18:10 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/545#comment:5 https://svn.boost.org/trac10/ticket/545#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/545#comment:4" title="Comment 4">vladimir_prus</a>: </p> <blockquote class="citation"> <p> You have set 'version' to 'Boost Development Trunk'. Have you actually tried with trunk? I guess not, since trunk appears to give your expected results on your testcase. Could you please double-check with trunk, and then mark this issue fixed again? </p> </blockquote> <p> You're right, trunk fixes the problem. I selected "Trunk" by mistake, sorry. Setting to "fixed" again. </p> Ticket