Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ def permute(*argv, **keywords)
#
def permute!(argv = default_argv, **keywords)
nonopts = []
order!(argv, **keywords, &nonopts.method(:<<))
order!(argv, **keywords) {|nonopt| nonopts << nonopt}
argv[0, 0] = nonopts
argv
end
Expand Down Expand Up @@ -1908,13 +1908,16 @@ def getopts(*args, symbolize_names: false, **keywords)
single_options, *long_options = *args

result = {}
setter = (symbolize_names ?
->(name, val) {result[name.to_sym] = val}
: ->(name, val) {result[name] = val})

single_options.scan(/(.)(:)?/) do |opt, val|
if val
result[opt] = nil
setter[opt, nil]
define("-#{opt} VAL")
else
result[opt] = false
setter[opt, false]
define("-#{opt}")
end
end if single_options
Expand All @@ -1923,16 +1926,16 @@ def getopts(*args, symbolize_names: false, **keywords)
arg, desc = arg.split(';', 2)
opt, val = arg.split(':', 2)
if val
result[opt] = val.empty? ? nil : val
setter[opt, (val unless val.empty?)]
define("--#{opt}=#{result[opt] || "VAL"}", *[desc].compact)
else
result[opt] = false
setter[opt, false]
define("--#{opt}", *[desc].compact)
end
end

parse_in_order(argv, result.method(:[]=), **keywords)
symbolize_names ? result.transform_keys(&:to_sym) : result
parse_in_order(argv, setter, **keywords)
result
end

#
Expand Down Expand Up @@ -1982,7 +1985,7 @@ def complete(typ, opt, icase = false, *pat) # :nodoc:
visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
}
exc = ambiguous ? AmbiguousOption : InvalidOption
raise exc.new(opt, additional: self.method(:additional_message).curry[typ])
raise exc.new(opt, additional: proc {|o| additional_message(typ, o)})
end
private :complete

Expand Down Expand Up @@ -2273,9 +2276,10 @@ def recover(argv)
argv
end

DIR = File.join(__dir__, '')
def self.filter_backtrace(array)
unless $DEBUG
array.delete_if(&%r"\A#{Regexp.quote(__FILE__)}:"o.method(:=~))
array.delete_if {|bt| bt.start_with?(DIR)}
end
array
end
Expand Down
Loading