Class: OptparseLite::Dispatcher

Inherits:
Object
  • Object
show all
Includes:
HelpHelper
Defined in:
lib/optparse-lite.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HelpHelper

#cmd, #hdr, #help_requested?, #looks_like_header?, #prefix, #txt

Constructor Details

#initialize(impl, spec, ui) ⇒ Dispatcher

Returns a new instance of Dispatcher.



293
294
295
296
297
298
# File 'lib/optparse-lite.rb', line 293

def initialize impl, spec, ui
  @impl = impl
  @spec = spec
  @ui = ui
  @help = Help.new(@spec, @ui)
end

Instance Attribute Details

#helpObject (readonly)

commands need some or all of these



300
301
302
# File 'lib/optparse-lite.rb', line 300

def help
  @help
end

#implObject (readonly)

commands need some or all of these



300
301
302
# File 'lib/optparse-lite.rb', line 300

def impl
  @impl
end

#specObject (readonly)

commands need some or all of these



300
301
302
# File 'lib/optparse-lite.rb', line 300

def spec
  @spec
end

#uiObject (readonly)

commands need some or all of these



300
301
302
# File 'lib/optparse-lite.rb', line 300

def ui
  @ui
end

Instance Method Details

#run(argv) ⇒ Object



301
302
303
304
305
306
307
308
309
# File 'lib/optparse-lite.rb', line 301

def run argv
  return @help.no_args         if argv.empty?
  return @help.requested(argv) if help_requested?(argv)
  if cmd = @help.find_one_loudly(argv.shift, @spec)
    cmd.run(self, argv)
  else
    -1 # kind of silly but whatever
  end
end