Class: Cloudit::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudit/command/base.rb

Direct Known Subclasses

Generate, Index, Validate

Constant Summary collapse

VALID_METHODS =
[]
OPTION_NAME_OFFSET =
6

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = []) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
# File 'lib/cloudit/command/base.rb', line 12

def initialize(args=[])
  @method = if args[0].is_a?(String) && args[0].include?('-')
    nil
  else
    args.shift.strip rescue nil
  end
  @opts = parser.parse(args)
end

Class Attribute Details

.parserObject

Returns the value of attribute parser.



6
7
8
# File 'lib/cloudit/command/base.rb', line 6

def parser
  @parser
end

.slop_optsObject

Returns the value of attribute slop_opts.



6
7
8
# File 'lib/cloudit/command/base.rb', line 6

def slop_opts
  @slop_opts
end

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cloudit/command/base.rb', line 21

def execute
  puts @method

  if @method.nil?
    index
  elsif self.class::VALID_METHODS.include?(@method)
    self.send(@method)
  else
    invalid_method
  end
end

#helpObject



37
38
39
# File 'lib/cloudit/command/base.rb', line 37

def help
  $stdout.puts slop_opts
end

#invalid_methodObject



33
34
35
# File 'lib/cloudit/command/base.rb', line 33

def invalid_method
  $stdout.puts "cloudit: '#{@method}' is not a cloudit command\nSee 'cloudit --help'"
end

#parserObject



41
42
43
# File 'lib/cloudit/command/base.rb', line 41

def parser
  self.class.parser
end

#slop_optsObject



45
46
47
# File 'lib/cloudit/command/base.rb', line 45

def slop_opts
  self.class.slop_opts
end