Boost C++ Libraries: Ticket #4781: Boost Program Options 'arg' text could be editiable. https://svn.boost.org/trac10/ticket/4781 <p> I have a minor feature request and that is that when I write out a program option that has an argument it comes out, for example, like this: </p> <pre class="wiki"> -m [ --log-file ] arg (=&lt;none&gt;) set log file. </pre><p> But that 'arg' does not look nice to me; I would rather that it read: </p> <pre class="wiki"> -m [ --log-file ] &lt;filename&gt; (=&lt;none&gt;) set log file. </pre><p> And I would like to be able to set that somehow in the po::value setup. I also checked to see if you could do this already and it seems as though you cannot in the boost::program_options source code itself starting on line 67 of value_semantic.cpp there is the following lines: </p> <div class="wiki-code"><div class="code"><pre><span class="n">BOOST_PROGRAM_OPTIONS_DECL</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">arg</span><span class="p">(</span><span class="s">&quot;arg&quot;</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">untyped_value</span><span class="o">::</span><span class="n">name</span><span class="p">()</span> <span class="k">const</span> <span class="p">{</span> <span class="k">return</span> <span class="n">arg</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> So since 'arg' seems to be set in stone I do not think that it is possible to do this yet. I would really like to know if you think this is a good idea or not. Thanks. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4781 Trac 1.4.3 Vladimir Prus Sat, 08 Jan 2011 10:35:16 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4781#comment:1 https://svn.boost.org/trac10/ticket/4781#comment:1 <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-new">wontfix</span> </li> </ul> <p> It does not seem to me that having the help output say that the value of "log-file" option is "&lt;filename&gt;" actually adds too much to user's understanding of the interface. This is precisely the reason why 'arg' is hardcoded, and I'm not planning on changing that. </p> Ticket Jacobo de Vera <devel@…> Mon, 07 Feb 2011 01:42:27 GMT <link>https://svn.boost.org/trac10/ticket/4781#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:2</guid> <description> <p> Could you please reconsider? Having a named "arg" helps writing better help messages, making it easier to refer to the argument by name. Lots of well known programs take advantage of this in their help messages (ls, vim, emacs, gcc, to name a few). This is an example from gcc: </p> <pre class="wiki">-B &lt;directory&gt; Add &lt;directory&gt; to the compiler's search paths </pre><p> The mention of a &lt;directory&gt; together with the B option makes it much easier to refer back to the option itself during its description, while keeping full semantics. </p> <p> Perhaps support for this could be added as a new public member of <code>boost::program_options::typed_value</code>, so that the string to be output can be passed when new options are being specified: </p> <div class="wiki-code"><div class="code"><pre> <span class="n">typed_value</span> <span class="o">*</span> <span class="nf">metavar</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="o">&amp;</span><span class="p">);</span> </pre></div></div><p> I'm using <code>metavar</code> only because that's the name I've seen for it in Python's optparse module, but it could very well be <code>argname</code> or whatever. </p> <p> Thank you. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Massaioli</dc:creator> <pubDate>Mon, 07 Feb 2011 02:08:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:3</guid> <description> <p> I cannot vote for a post but I agree with what Jacobo said in terms of making it clearer and easier to understand in the help messages. I have learned to live with this but I still believe that this would be handy if we could change it from "arg". </p> </description> <category>Ticket</category> </item> <item> <author>lukasz.dobrogowski@…</author> <pubDate>Wed, 08 Jun 2011 19:34:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:4</guid> <description> <p> I'm also voting for this. It would largely help with migration from existing commandline parsing systems in projects to boost::program_options with as little changes to syntax and usability as possible. </p> <p> Example from Wesnoth: fragment of --help before PO: --preprocess, -p &lt;file/folder&gt; &lt;target directory&gt; (short description) </p> <p> fragment of --help after using PO: -p [ --preprocess ] arg (long description, arg has to be explained in it and it isn't immediately visible that the option takes two tokens) </p> <p> It's probably most useful for multitoken commands with custom validators, where it would really help usability to be able to explain needed arguments with string such as "&lt;myarg1&gt; &lt;myarg2&gt;"... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Wed, 08 Jun 2011 19:37:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:5</guid> <description> <p> I'd like to clarify that while I personally will not be working on this (that's the reason for the current 'wontfix' resolution), there appears to be popular demand, and therefore I will accept a patch to implement this feature, if said patch is OK technically. </p> </description> <category>Ticket</category> </item> <item> <author>mathstuf@…</author> <pubDate>Fri, 04 Nov 2011 17:19:10 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/4781 https://svn.boost.org/trac10/ticket/4781 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">0001-Add-support-for-a-metavar-in-typed_value.patch</span> </li> </ul> <p> Patch to add metavar method to typed_value </p> Ticket mathstuf@… Fri, 04 Nov 2011 17:21:15 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/4781#comment:6 https://svn.boost.org/trac10/ticket/4781#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">wontfix</span> </li> </ul> <p> I attached a patch to add the metavar method as well as updating the name method to make use of it. </p> <p> I haven't updated the documentation other than the comment in the code because I haven't found where to update it. I see the HTML under doc/html/program_options, but it seems like there'd be a more canonical place to change it. </p> Ticket Leo Goodstadt <boost@…> Mon, 14 Nov 2011 01:33:22 GMT <link>https://svn.boost.org/trac10/ticket/4781#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:7</guid> <description> <p> I would like to add my support to this feature, having long patched my version of program_options to support this. </p> <p> The text of "arg" is called "metavar" in the python optparse module, and opt_name in GNU genparse. I am very used to "metavar" from python but it is very obscure for non-python users. </p> <p> "arg" is either the name of the argument/value for the option, or a placeholder for the argument/value for the option. In use, it is commonly the *type* of the argument. </p> <p> So we have four choices: 1) metavar (from python) 2) argument_name | arg_name | option_value_name | value_name 3) argument_placeholder_name | arg_placeholder | value_placeholder 4) argument_type | arg_type </p> <p> My preference is for something from (2). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 14 Dec 2011 12:34:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:8</guid> <description> <p> +1. This would be very useful for my project. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Sun, 08 Apr 2012 09:22:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:9</guid> <description> <p> I would prefer 'argument_name'. Does anybody want to argue for a different name, before I commit this patch? </p> </description> <category>Ticket</category> </item> <item> <author>robertmassaioli@…</author> <pubDate>Sun, 08 Apr 2012 09:28:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:10</guid> <description> <p> No it looks good to me too and I also prefer 'argument_name' because it is says exactly what it means and maintains the 'arg' naming that has been used so far. Thank you very much for including this change and thank you mathstuf for writing it. I will be incorporating it in my code immediately. (Also a one line addition to the documentation is probably required but we know this already). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Thu, 12 Apr 2012 08:37:40 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4781#comment:11 https://svn.boost.org/trac10/ticket/4781#comment:11 <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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/77931" title="Allow to specify how option's value is named in help message. Fixes ...">[77931]</a>) Allow to specify how option's value is named in help message. </p> <p> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4781" title="#4781: Feature Requests: Boost Program Options 'arg' text could be editiable. (closed: fixed)">#4781</a>. </p> Ticket anonymous Thu, 12 Apr 2012 09:18:55 GMT <link>https://svn.boost.org/trac10/ticket/4781#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:12</guid> <description> <p> I have decided to go with 'value_name', since essentially all of the code is using 'option' and 'value' terminology. The use of 'arg' as default help output can be though as bad idea -- which is not worth fixing, probably. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Thu, 12 Apr 2012 09:40:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:13</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/77932" title="Merge: Allow to specify how option's value is named in help message. ...">[77932]</a>) Merge: Allow to specify how option's value is named in help message. </p> <p> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4781" title="#4781: Feature Requests: Boost Program Options 'arg' text could be editiable. (closed: fixed)">#4781</a>. </p> </description> <category>Ticket</category> </item> <item> <author>TLBettens@…</author> <pubDate>Sat, 18 Aug 2012 21:49:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:14</guid> <description> <h2 class="section" id="Warningintroducedinrelease1_50_0">Warning introduced in release 1_50_0</h2> <p> Function <strong>set_option_name</strong> in class <strong>error_with_no_option_name</strong> was introduced into file .../boost_1_50_0/boost/program_options/errors.hpp causing Visual C++ version 10, perhaps others, to emit the following warning message when compiled with warning level 4 (/W4) enabled: </p> <pre class="wiki">1&gt;c:\boostbuilding\boost_1_50_0\boost\program_options\errors.hpp(253): warning C4100: 'option_name' : unreferenced formal parameter </pre><p> Unused arguments should remain unnamed, and the workaround is something like this: </p> <pre class="wiki">252: /** Does NOT set option name, because no option name makes sense */ 253: virtual void set_option_name(const std::string&amp; /* option_name */){} </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Sun, 19 Aug 2012 07:26:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:15</guid> <description> <p> Thanks for the report. However, this is already fixed, on trunk and release branch, and should be fixed in 1.51 when it is released. </p> </description> <category>Ticket</category> </item> <item> <author>pbf@…</author> <pubDate>Thu, 13 Dec 2012 07:36:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4781#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4781#comment:16</guid> <description> <p> I'm encountering a problem, whereby I have a shared library that statically links to program_options, and an application that also statically links to it, but dynamically links to the shared library. When the program terminates, it tries to double delete the string "arg", causing potential heap corruption. </p> <p> While I'm aware that this usage of boost violates the one definition rule, and is generally dangerous, I need to do it anyway.. </p> <p> I've managed to resolve the issue by patching my version of program_options with the following changes: </p> <p> value_semantic.cpp </p> <pre class="wiki">85: BOOST_PROGRAM_OPTIONS_DECL char* arg = "arg"; </pre><p> value_semantic.hpp </p> <pre class="wiki">13: extern BOOST_PROGRAM_OPTIONS_DECL char* arg; 19: const std::string var = (m_value_name.empty() ? arg : m_value_name); </pre><p> I'd like to suggest this as a patch for the next release, since I'm sure I'm not the only one who's encountered this problem. (In fact, someone already did, last year in the boost Users forum) </p> </description> <category>Ticket</category> </item> </channel> </rss>