https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-12-09T23:12:27ZRuby Issue Tracking SystemRuby master - Bug #7537: OptionParser treats negative digits as optionshttps://bugs.ruby-lang.org/issues/7537?journal_id=345622012-12-09T23:12:27Zprijutme4ty (Ilya Vorontsov)prijutme4ty@gmail.com
<ul></ul><p>In my opinion, negative numbers shouldn't be treated as option keys unless it was explicitly specified. In other cases them should be treated as usual parameters.</p> Ruby master - Bug #7537: OptionParser treats negative digits as optionshttps://bugs.ruby-lang.org/issues/7537?journal_id=345762012-12-10T13:47:34Zzzak (zzak _)
<ul><li><strong>Category</strong> set to <i>lib</i></li><li><strong>Assignee</strong> set to <i>nobu (Nobuyoshi Nakada)</i></li></ul> Ruby master - Bug #7537: OptionParser treats negative digits as optionshttps://bugs.ruby-lang.org/issues/7537?journal_id=349552012-12-21T22:23:32Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li></ul> Ruby master - Bug #7537: OptionParser treats negative digits as optionshttps://bugs.ruby-lang.org/issues/7537?journal_id=376952013-03-18T21:52:53Zprijutme4ty (Ilya Vorontsov)prijutme4ty@gmail.com
<ul></ul><p>Sent a pull-request. <a href="https://github.com/ruby/ruby/pull/259" class="external">https://github.com/ruby/ruby/pull/259</a><br>
I've made changes the same way as python do -- <a href="http://docs.python.org/dev/library/argparse.html#arguments-containing" class="external">http://docs.python.org/dev/library/argparse.html#arguments-containing</a><br>
This patch introduces one possible (but not very serious and very rare) incompatibility: if one already uses explicitly defined negative-digit option such as '-1' and also uses an option with optional argument '-p [ARG]' and runs a command with options '-p -1' then before patch it'll be treated as two different options '-p', '-1' and after patch they are treated as an option '-p' with value '-1'.<br>
If one meets this problem, he can use option declaration with equal sign: '-p=[ARG]' or just change places of arguments and run his program with options '-1 -p'.<br>
But I suppose not too many people use explicitly defined numeric options and even less people use optional argument with them in such order (may be even nobody use it such a way).</p>
<p>Also, if possible, backporting into 1.9 of this patch will be very useful. Unfortunately I don't know how should I do this.</p> Ruby master - Bug #7537: OptionParser treats negative digits as optionshttps://bugs.ruby-lang.org/issues/7537?journal_id=382462013-04-05T11:38:28Zzzak (zzak _)
<ul><li><strong>File</strong> <a href="/attachments/3641">259.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/3641/259.patch">259.patch</a> added</li></ul><p>I've attached the patch from the associated pull request.</p> Ruby master - Bug #7537: OptionParser treats negative digits as optionshttps://bugs.ruby-lang.org/issues/7537?journal_id=417832013-09-13T04:48:12Zprijutme4ty (Ilya Vorontsov)prijutme4ty@gmail.com
<ul></ul><p>Any thoughts about this patch?</p> Ruby master - Bug #7537: OptionParser treats negative digits as optionshttps://bugs.ruby-lang.org/issues/7537?journal_id=804462019-08-07T16:33:55Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>I don't think this is a bug, I think this is expected behavior. When parsing <code>-p -1</code>, where <code>-p</code> accepts an optional argument, OptionParser correctly treats the <code>-1</code> as a new option, and raises an error as the parser does not accept that option. You have to specify the optional argument a different way to tell OptionParser that the <code>-1</code> is the value for the optional argument. One way is <code>-p-1</code>, another is <code>--pvalue=-1</code>.</p>