Class: Cloudit::Command::Base

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

Direct Known Subclasses

Generate, Index

Constant Summary collapse

VALID_METHODS =
[]
OPTION_NAME_OFFSET =
6

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

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

.parserObject

Returns the value of attribute parser.



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

def parser
  @parser
end

.slop_optsObject

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

#commandsObject

Returns the value of attribute commands.



8
9
10
# File 'lib/cloudit/command/base.rb', line 8

def commands
  @commands
end

Instance Method Details

#executeObject



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

#helpObject



39
40
41
# File 'lib/cloudit/command/base.rb', line 39

def help
  $stdout.puts slop_opts
end

#invalid_methodObject



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

#parserObject



43
44
45
# File 'lib/cloudit/command/base.rb', line 43

def parser
  self.class.parser
end

#slop_optsObject



47
48
49
# File 'lib/cloudit/command/base.rb', line 47

def slop_opts
  self.class.slop_opts
end