lib/getopt/long.rb in getopt-1.3.3 vs lib/getopt/long.rb in getopt-1.3.4
- old
+ new
@@ -7,11 +7,11 @@
NEGATABLE = 4
class LongError < StandardError; end
class Long
- VERSION = "1.3.3"
+ VERSION = "1.3.4"
# Takes an array of switches. Each array consists of three elements.
def self.getopts(*switches)
if switches.empty?
raise ArgumentError, "no switches provided"
@@ -52,13 +52,13 @@
types[char] = switch[2] # Set type for short switch
valid.push(char) # Set valid short switches
}
}
- re_long = /^(--\w+)$/
+ re_long = /^(--\w+[-\w+]*)?$/
re_short = /^(-\w)$/
- re_long_eq = /^(--\w+?)=(.*?)$|^(-\w?)=(.*?)$/
+ re_long_eq = /^(--\w+[-\w+]*)?=(.*?)$|(-\w?)=(.*?)$/
re_short_sq = /^(-\w)(\S+?)$/
ARGV.each_with_index{ |opt, index|
# Allow either -x -v or -xv style for single char args
@@ -194,10 +194,14 @@
end
}
# Get rid of leading "--" and "-" to make it easier to reference
hash.each{ |key, value|
- nkey = key.tr("-","")
+ if key[0,2] == '--'
+ nkey = key.sub('--', '')
+ else
+ nkey = key.sub('-', '')
+ end
hash.delete(key)
hash[nkey] = value
}
hash