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.
17 18 19 20 |
# File 'lib/cl/runner/default.rb', line 17 def initialize(ctx, args) @ctx = ctx @const, @args = lookup(args) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
15 16 17 |
# File 'lib/cl/runner/default.rb', line 15 def args @args end |
#const ⇒ Object (readonly)
Returns the value of attribute const.
15 16 17 |
# File 'lib/cl/runner/default.rb', line 15 def const @const end |
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
15 16 17 |
# File 'lib/cl/runner/default.rb', line 15 def ctx @ctx end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
15 16 17 |
# File 'lib/cl/runner/default.rb', line 15 def opts @opts end |
Instance Method Details
#cmd ⇒ Object
28 29 30 |
# File 'lib/cl/runner/default.rb', line 28 def cmd @cmd ||= const.new(ctx, args) end |
#help ⇒ Object
32 33 34 |
# File 'lib/cl/runner/default.rb', line 32 def help Help.new(ctx, [cmd.registry_key]) end |
#run ⇒ Object
22 23 24 25 26 |
# File 'lib/cl/runner/default.rb', line 22 def run cmd.help? ? help.run : cmd.run rescue OptionParser::InvalidOption => e raise UnknownOption.new(const, e.) end |
#suggestions(args) ⇒ Object
36 37 38 39 |
# File 'lib/cl/runner/default.rb', line 36 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 |