Issue #11523 has been updated by Vit Ondruch.


I believe that:

1. This is what OptParser doing by default. If your code were `opts.on("--irs [OCTAL]", OptionParser::OctalInteger,`, i.e. without the '-F', you would get '--irs' as well as shorthand '-i' available. Your case is bit specific, that the short and long parameters are quite different.
2. If you override the '-i' option somewhere and give it different meaning, the OptParser will handle it correctly.
3. If you really want to avoid the default short version of '-i', I can't see anything easier then fire the OptionParser::InvalidOption in the '-i' handler.

----------------------------------------
Bug #11523: optparse short options will match complete options
https://bugs.ruby-lang.org/issues/11523#change-56963

* Author: Micha J
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
In short, if I define an option like `"-F", "--irs [OCTAL]"`, `-i` will match this option, although the short version is defined as `-F`.

----

In long, this can be quite troublesome:

See the provided example

http://ruby-doc.org/stdlib-2.2.0/libdoc/optparse/rdoc/OptionParser.html

and change or remove the `"-i", "--inplace [EXTENSION]"` option for something else than `i`:

Now, the -i will still match, but the other option `"-F", "--irs [OCTAL]"`!

In a more complete stack this resulted in a hard to find error. Also, to fix this (and raise the required error) you need to check the ARGV directly which renders optparse a bit less useful.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>