Class: CP::Command
- Includes:
- Has::Commands, Has::Options
- Defined in:
- lib/cp/command.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#summary ⇒ Object
Returns the value of attribute summary.
Instance Method Summary collapse
- #action(&block) ⇒ Object
- #action=(block) ⇒ Object
-
#initialize(name, parent = nil) {|_self| ... } ⇒ Command
constructor
A new instance of Command.
Methods included from Has::Options
Methods included from Has::Commands
Constructor Details
#initialize(name, parent = nil) {|_self| ... } ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cp/command.rb', line 9 def initialize( name, parent=nil ) unless name.respond_to?( :to_sym ) raise ArgumentError.new( "name must be a Symbol (or respond to .to_sym)") end @parent = parent @name = name.to_sym yield self if block_given? end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
7 8 9 |
# File 'lib/cp/command.rb', line 7 def default @default end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/cp/command.rb', line 7 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/cp/command.rb', line 6 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/cp/command.rb', line 6 def parent @parent end |
#summary ⇒ Object
Returns the value of attribute summary.
7 8 9 |
# File 'lib/cp/command.rb', line 7 def summary @summary end |
Instance Method Details
#action(&block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cp/command.rb', line 20 def action( &block ) if !block_given? @action else @action = lambda { |args| begin opts = rescue CP::MissingOptionError => e CP::App.instance.fatal( "'#{e}' is required" ) end block.call( args, opts ) CP::HighLine.instance.say_buffer } end end |
#action=(block) ⇒ Object
37 38 39 |
# File 'lib/cp/command.rb', line 37 def action=( block ) action( &block ) end |