[#70843] Re: [ruby-cvs:58952] hsbt:r51801 (trunk): * lib/rubygems: Update to RubyGems HEAD(fe61e4c112). — Eric Wong <normalperson@...>
hsbt@ruby-lang.org wrote:
3 messages
2015/09/17
[ruby-core:70897] [Ruby trunk - Bug #11523] optparse short options will match complete options
From:
shishir127@...
Date:
2015-09-24 04:49:17 UTC
List:
ruby-core #70897
Issue #11523 has been updated by Shishir Joshi.
Try executing this script. The only difference between the previous script and this one is that instead of returning the `options` variable, `opt_parser.parse!(args)` is being returned from the method. I did not get the error with this script.
~~~
require 'optparse'
require 'pp'
class OptparseExample
def self.parse(args)
options = {}
opt_parser = OptionParser.new do |opts|
opts.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
"Specify record separator (default \\0)") do |rs|
options["trigger"] = "I got triggered"
end
end
opt_parser.parse!(args)
end # parse()
end # class OptparseExample
options = OptparseExample.parse(ARGV)
pp options
pp ARGV
~~~
----------------------------------------
Bug #11523: optparse short options will match complete options
https://bugs.ruby-lang.org/issues/11523#change-54266
* 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/