Class: Cl::Runner::Default

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Merge, Suggest
Defined in:
lib/cl/runner/default.rb

Constant Summary

Constants included from Merge

Merge::MERGE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Merge

#merge

Methods included from Suggest

#suggest

Constructor Details

#initialize(ctx, args) ⇒ Default

Returns a new instance of Default.


20
21
22
23
# File 'lib/cl/runner/default.rb', line 20

def initialize(ctx, args)
  @ctx = ctx
  @const, @args = lookup(args)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args


18
19
20
# File 'lib/cl/runner/default.rb', line 18

def args
  @args
end

#constObject (readonly)

Returns the value of attribute const


18
19
20
# File 'lib/cl/runner/default.rb', line 18

def const
  @const
end

#ctxObject (readonly)

Returns the value of attribute ctx


18
19
20
# File 'lib/cl/runner/default.rb', line 18

def ctx
  @ctx
end

#optsObject (readonly)

Returns the value of attribute opts


18
19
20
# File 'lib/cl/runner/default.rb', line 18

def opts
  @opts
end

Instance Method Details

#cmdObject


31
32
33
# File 'lib/cl/runner/default.rb', line 31

def cmd
  @cmd ||= const.new(ctx, args)
end

#helpObject


35
36
37
# File 'lib/cl/runner/default.rb', line 35

def help
  cmd.is_a?(Help) ? cmd : Help.new(ctx, [cmd.registry_key])
end

#runObject


25
26
27
28
29
# File 'lib/cl/runner/default.rb', line 25

def run
  cmd.help? ? help.run : cmd.send(self.class.run_method)
rescue OptionParser::InvalidOption => e
  raise UnknownOption.new(const, e.message)
end

#suggestions(args) ⇒ Object


39
40
41
42
# File 'lib/cl/runner/default.rb', line 39

def suggestions(args)
  keys = args.inject([]) { |keys, arg| keys << [keys.last, arg].compact.join(':') }
  keys.map { |key| suggest(providers.map(&:to_s), key) }.flatten
end