lib/getopt/long.rb in getopt-1.3.4 vs lib/getopt/long.rb in getopt-1.3.5
- old
+ new
@@ -3,15 +3,16 @@
REQUIRED = 0
BOOLEAN = 1
OPTIONAL = 2
INCREMENT = 3
NEGATABLE = 4
+ NUMERIC = 5
class LongError < StandardError; end
class Long
- VERSION = "1.3.4"
+ VERSION = '1.3.5'
# Takes an array of switches. Each array consists of three elements.
def self.getopts(*switches)
if switches.empty?
raise ArgumentError, "no switches provided"
@@ -31,23 +32,24 @@
# Set our list of valid switches, and proper types for each switch
switches.each{ |switch|
valid.push(switch[0]) # Set valid long switches
# Set type for long switch, default to BOOLEAN.
- # Create synonym hash. Default to first char of long switch for
- # short switch, e.g. "--verbose" creates a "-v" synonym.
if switch[1].kind_of?(Fixnum)
switch[2] = switch[1]
types[switch[0]] = switch[2]
switch[1] = switch[0][1..2]
else
switch[2] ||= BOOLEAN
types[switch[0]] = switch[2]
switch[1] ||= switch[0][1..2]
end
- syns[switch[0]] = switch[1]
- syns[switch[1]] = switch[0]
+ # Create synonym hash. Default to first char of long switch for
+ # short switch, e.g. "--verbose" creates a "-v" synonym. The same
+ # synonym can only be used once - first one wins.
+ syns[switch[0]] = switch[1] unless syns[switch[1]]
+ syns[switch[1]] = switch[0] unless syns[switch[1]]
switch[1].each{ |char|
types[char] = switch[2] # Set type for short switch
valid.push(char) # Set valid short switches
}