Class: Cl::Runner::Default
- Inherits:
-
Object
- Object
- Cl::Runner::Default
- Extended by:
- Forwardable
- Defined in:
- lib/cl/runner/default.rb
Constant Summary
Constants included from Merge
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#const ⇒ Object
readonly
Returns the value of attribute const.
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #cmd ⇒ Object
- #help ⇒ Object
-
#initialize(ctx, args) ⇒ Default
constructor
A new instance of Default.
- #run ⇒ Object
- #suggestions(args) ⇒ Object
Methods included from Merge
Methods included from 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
#args ⇒ Object (readonly)
Returns the value of attribute args.
18 19 20 |
# File 'lib/cl/runner/default.rb', line 18 def args @args end |
#const ⇒ Object (readonly)
Returns the value of attribute const.
18 19 20 |
# File 'lib/cl/runner/default.rb', line 18 def const @const end |
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
18 19 20 |
# File 'lib/cl/runner/default.rb', line 18 def ctx @ctx end |
#opts ⇒ Object (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
#cmd ⇒ Object
31 32 33 |
# File 'lib/cl/runner/default.rb', line 31 def cmd @cmd ||= const.new(ctx, args) end |
#help ⇒ Object
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 |
#run ⇒ Object
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.) 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 |