2016-10-14 09:26:13 -04:00
|
|
|
# frozen_string_literal: true
|
2022-01-04 02:32:45 -05:00
|
|
|
require_relative '../optparse'
|
2016-10-14 09:26:13 -04:00
|
|
|
|
|
|
|
class OptionParser
|
2021-03-28 13:24:21 -04:00
|
|
|
# :call-seq:
|
|
|
|
# define_by_keywords(options, method, **params)
|
|
|
|
#
|
2021-04-10 20:03:07 -04:00
|
|
|
# :include: ../../doc/optparse/creates_option.rdoc
|
2021-04-07 12:58:46 -04:00
|
|
|
#
|
2016-10-14 09:26:13 -04:00
|
|
|
def define_by_keywords(options, meth, **opts)
|
|
|
|
meth.parameters.each do |type, name|
|
|
|
|
case type
|
|
|
|
when :key, :keyreq
|
|
|
|
op, cl = *(type == :key ? %w"[ ]" : ["", ""])
|
|
|
|
define("--#{name}=#{op}#{name.upcase}#{cl}", *opts[name]) do |o|
|
|
|
|
options[name] = o
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
options
|
|
|
|
end
|
|
|
|
end
|