class IDL::OptionList
def define_switch(switch, options = {}, &block)
def define_switch(switch, options = {}, &block) switch = switch.to_s raise "switch types mismatch" if @options.has_key?(switch) && options[:type] && options[:type] != @options[switch].type @options[switch] ||= Option.new(switch, options) block.call(Option::Configurator.new(@options[switch])) if block_given? end
def initialize
def initialize @options = {} end
def to_option_parser(optp, option_holder)
def to_option_parser(optp, option_holder) @options.each do |sw, op| (arg_list = [sw]) << op.type arg_list.concat(op.description(optp.summary_indent)) optp.on(*arg_list) do |v| op.run(v, option_holder.options) end optp.separator '' if op.separator end end
def undefine_switch(switch)
def undefine_switch(switch) switch = switch.to_s @options.delete(switch) end