Class: IDL::OptionList

Inherits:
Object
  • Object
show all
Defined in:
lib/ridl/optparse_ext.rb

Defined Under Namespace

Classes: Option

Instance Method Summary collapse

Constructor Details

#initializeOptionList

Option



326
327
328
# File 'lib/ridl/optparse_ext.rb', line 326

def initialize()
  @options = {}
end

Instance Method Details

#define_switch(switch, options = {}, &block) ⇒ Object Also known as: for_switch, switch

Raises:

  • (RuntimeError)


330
331
332
333
334
335
# File 'lib/ridl/optparse_ext.rb', line 330

def define_switch(switch, options = {}, &block)
  switch = switch.to_s
  raise RuntimeError, "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

#to_option_parser(optp, option_holder) ⇒ Object



344
345
346
347
348
349
350
351
352
353
# File 'lib/ridl/optparse_ext.rb', line 344

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

#undefine_switch(switch) ⇒ Object



339
340
341
342
# File 'lib/ridl/optparse_ext.rb', line 339

def undefine_switch(switch)
  switch = switch.to_s
  @options.delete(switch)
end