Class: Cody::CLI::Base

Inherits:
Object
  • Object
show all
Includes:
AwsServices
Defined in:
lib/cody/cli/base.rb

Direct Known Subclasses

Badge, Deploy, Logs, Status, Stop

Instance Method Summary collapse

Methods included from AwsServices

#cfn, #codebuild

Methods included from AwsServices::Helpers

#are_you_sure?, #find_stack, #inferred_project_name, #inferred_stack_name, #normalize_stack_name, #project_name_convention, #stack_exists?

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
# File 'lib/cody/cli/base.rb', line 6

def initialize(options)
  @options = options
  @project_name = options[:project_name] || inferred_project_name
  @full_project_name = project_name_convention(@project_name)
end

Instance Method Details

#build_idObject



21
22
23
24
25
26
# File 'lib/cody/cli/base.rb', line 21

def build_id
  return @options[:build_id] if @options[:build_id]

  resp = codebuild.list_builds_for_project(project_name: @full_project_name)
  resp.ids.first # most recent build_id
end

#check_build_id!Object



28
29
30
31
32
# File 'lib/cody/cli/base.rb', line 28

def check_build_id!
  return if build_id
  puts "WARN: No builds found for #{@project_name.color(:green)} project"
  exit
end

#run_with_exception_handlingObject



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

def run_with_exception_handling
  yield
rescue Aws::CodeBuild::Errors::ResourceNotFoundException => e
  puts "ERROR: #{e.class}: #{e.message}".color(:red)
  puts "CodeBuild project #{@full_project_name} not found."
rescue Aws::CodeBuild::Errors::InvalidInputException => e
  puts "ERROR: #{e.class}: #{e.message}".color(:red)
end