Module: OptparseLite::ServiceClass

Included in:
ServiceModuleSingleton
Defined in:
lib/optparse-lite.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#specObject (readonly) Also known as: app

Returns the value of attribute spec.



527
528
529
# File 'lib/optparse-lite.rb', line 527

def spec
  @spec
end

#uiObject (readonly)

Returns the value of attribute ui.



527
528
529
# File 'lib/optparse-lite.rb', line 527

def ui
  @ui
end

Instance Method Details

#init_service_class(spec_class) ⇒ Object



521
522
523
524
525
526
# File 'lib/optparse-lite.rb', line 521

def init_service_class spec_class
  @argv_hook = nil
  @instance ||= nil
  @spec = spec_class.new(self)
  @ui = Ui.new
end

#method_added(method_sym) ⇒ Object



558
559
560
# File 'lib/optparse-lite.rb', line 558

def method_added method_sym
  @spec.method_added_notify method_sym
end

#o(usage) ⇒ Object Also known as: usage



529
530
531
# File 'lib/optparse-lite.rb', line 529

def o usage
  @spec.usage usage
end

#opts(mixed = nil, &block) ⇒ Object



532
533
534
# File 'lib/optparse-lite.rb', line 532

def opts mixed=nil, &block
  @spec.opts(mixed, &block)
end

#run(argv = ARGV) ⇒ Object



536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/optparse-lite.rb', line 536

def run argv=ARGV
  @argv_hook.call(argv) if @argv_hook
  argv = argv.dup # never change caller's array
  return @ui.err.puts('run disabled. (probably for gentesting)') unless
    OptparseLite.run_enabled?
  unless @instance # rcov bug?
    obj = new
    obj.init_service_object(@spec, @ui)
    @instance = obj
  end
  @instance.run argv
end

#set_argv_hook(&hook) ⇒ Object



548
549
550
# File 'lib/optparse-lite.rb', line 548

def set_argv_hook &hook
  @argv_hook = hook
end

#subcommands(*a) ⇒ Object



551
552
553
# File 'lib/optparse-lite.rb', line 551

def subcommands *a
  @spec.subcommands(*a)
end

#x(desc) ⇒ Object Also known as: desc



554
555
556
# File 'lib/optparse-lite.rb', line 554

def x desc
  @spec.cmd_desc desc
end