Class: Cloudit::Command::Base
- Inherits:
-
Object
- Object
- Cloudit::Command::Base
- Defined in:
- lib/cloudit/command/base.rb
Constant Summary collapse
- VALID_METHODS =
[]
- OPTION_NAME_OFFSET =
6
Class Attribute Summary collapse
-
.parser ⇒ Object
Returns the value of attribute parser.
-
.slop_opts ⇒ Object
Returns the value of attribute slop_opts.
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
Instance Method Summary collapse
- #execute ⇒ Object
- #help ⇒ Object
-
#initialize(args = [], commands) ⇒ Base
constructor
A new instance of Base.
- #invalid_method ⇒ Object
- #parser ⇒ Object
- #slop_opts ⇒ Object
Constructor Details
#initialize(args = [], commands) ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 19 20 21 |
# File 'lib/cloudit/command/base.rb', line 13 def initialize(args=[], commands) @method = if args[0].is_a?(String) && args[0].include?('-') nil else args.shift.strip rescue nil end @opts = parser.parse(args) @commands = commands end |
Class Attribute Details
.parser ⇒ Object
Returns the value of attribute parser.
5 6 7 |
# File 'lib/cloudit/command/base.rb', line 5 def parser @parser end |
.slop_opts ⇒ Object
Returns the value of attribute slop_opts.
5 6 7 |
# File 'lib/cloudit/command/base.rb', line 5 def slop_opts @slop_opts end |
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
8 9 10 |
# File 'lib/cloudit/command/base.rb', line 8 def commands @commands end |
Instance Method Details
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cloudit/command/base.rb', line 23 def execute puts @method if @method.nil? index elsif self.class::VALID_METHODS.include?(@method) self.send(@method) else invalid_method end end |
#help ⇒ Object
39 40 41 |
# File 'lib/cloudit/command/base.rb', line 39 def help $stdout.puts slop_opts end |
#invalid_method ⇒ Object
35 36 37 |
# File 'lib/cloudit/command/base.rb', line 35 def invalid_method $stdout.puts "cloudit: '#{@method}' is not a cloudit command\nSee 'cloudit --help'" end |
#parser ⇒ Object
43 44 45 |
# File 'lib/cloudit/command/base.rb', line 43 def parser self.class.parser end |
#slop_opts ⇒ Object
47 48 49 |
# File 'lib/cloudit/command/base.rb', line 47 def slop_opts self.class.slop_opts end |