-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Description
OptionParser object doesn't work correctly when both Integer
and enum values (such as [1, 2, 3]
or ["1", "2", "3"]
) specified.
- When
Integer
and[1, 2, 3]
specified,OptionParser::InvalidArgument
will be raised unexpectedly. - When
Integer
and["1", "2", "3"]
specified, no exceptions will be raised but the option value will be remained as a string (expected to be converted into an integer value).
Example script:
require 'optparse'
parser = OptionParser.new
parser.on("-a <N>", "int #1", Integer)
parser.on("-b <N>", "int #2", Integer, [1,2,3]) # with enum (integer)
parser.on("-c <N>", "int #3", Integer, ["1", "2"]) # with enum (string)
## Without enum, parser parses args successfully.
opts = {}
parser.parse(["-a", "2"], into: opts) # ok
p opts #=> {:a=>2}
## [BUG] With enum (integer), parser raises InvalidArgument error.
opts = {}
#parser.parse(["-b", "2"], into: opts) #=> OptionParser::InvalidArgument
## [BUG] With enum (string), parser doesn't convert value into an integer.
opts = {}
parser.parse(["-c", "2"], into: opts) # no exception
p opts #=> {:c=>"2"} (expected: {:c=>2})
Environment:
- Version: optparse 0.4.0 & 0.5.0 (github repo)
- Ruby: 3.3.5
If allowed, I can submit a pull request for this bug. Let me know if you need it.
Metadata
Metadata
Assignees
Labels
No labels