Class: ECSHelper::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/ecs_helper/command/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#console, #error, #log

Constructor Details

#initialize(helper) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
# File 'lib/ecs_helper/command/base.rb', line 10

def initialize(helper)
  @client = helper.client
  @helper = helper
  @option_parser, @options = cmd_option_parser
  @option_parser.parse!(into: @options)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/ecs_helper/command/base.rb', line 7

def client
  @client
end

#helperObject

Returns the value of attribute helper.



7
8
9
# File 'lib/ecs_helper/command/base.rb', line 7

def helper
  @helper
end

#option_parserObject

Returns the value of attribute option_parser.



7
8
9
# File 'lib/ecs_helper/command/base.rb', line 7

def option_parser
  @option_parser
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/ecs_helper/command/base.rb', line 7

def options
  @options
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/ecs_helper/command/base.rb', line 7

def type
  @type
end

Instance Method Details

#applicationObject



34
35
36
# File 'lib/ecs_helper/command/base.rb', line 34

def application
  helper.application
end

#check_bin(bin) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/ecs_helper/command/base.rb', line 25

def check_bin(bin)
  check_cmd = Terrapin::CommandLine.new("which #{bin}")
  result = check_cmd.run
  "success"
rescue Terrapin::CommandNotFoundError, Terrapin::ExitStatusError => e
  messages = ["#{bin} not found"]
  raise ECSHelper::Error::BinNotFound.new(messages)
end

#printable?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/ecs_helper/command/base.rb', line 55

def printable?
  false
end

#projectObject



21
22
23
# File 'lib/ecs_helper/command/base.rb', line 21

def project
  helper.project
end

#requiredObject



51
52
53
# File 'lib/ecs_helper/command/base.rb', line 51

def required
  []
end

#validateObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ecs_helper/command/base.rb', line 38

def validate
  required.each do |r|
    value = options[r]
    if value.nil?
      messages = [
        "'#{r}' required for command '#{type}'".light_white,
        option_parser.help
      ]
      raise ECSHelper::Error::CommandValidationError.new(messages)
    end
  end
end