class CFnDK::Command

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/cfndk/command.rb, line 8
def exit_on_failure?
  true
end

Public Instance Methods

create() click to toggle source
# File lib/cfndk/command.rb, line 51
def create
  CFnDK.logger.info 'create...'.color(:green)
  data = load_config_data(options)
  credentials = resolve_credential(data, options)
  global_config = CFnDK::GlobalConfig.new(data, options)
  stacks = CFnDK::Stacks.new(data, options, credentials)
  keypairs = CFnDK::KeyPairs.new(data, options, credentials)

  global_config.pre_command_execute
  stacks.pre_command_execute
  stacks.validate
  keypairs.pre_command_execute
  keypairs.create
  keypairs.post_command_execute
  stacks.create
  stacks.post_command_execute
  global_config.post_command_execute
  return 0
rescue => e
  CFnDK.logger.error "#{e.class}: #{e.message}".color(:red)
  e.backtrace_locations.each do |line|
    CFnDK.logger.debug line
  end
  return 1
end
destroy() click to toggle source
# File lib/cfndk/command.rb, line 81
def destroy
  CFnDK.logger.info 'destroy...'.color(:green)
  data = load_config_data(options)
  credentials = resolve_credential(data, options)

  stacks = CFnDK::Stacks.new(data, options, credentials)
  keypairs = CFnDK::KeyPairs.new(data, options, credentials)

  if options[:force] || yes?('Are you sure you want to destroy? (y/n)', :yellow)
    stacks.destroy
    keypairs.destroy
    return 0
  else
    CFnDK.logger.info 'destroy command was canceled'.color(:green)
    return 2
  end
rescue => e
  CFnDK.logger.error "#{e.class}: #{e.message}".color(:red)
  e.backtrace_locations.each do |line|
    CFnDK.logger.debug line
  end
  return 1
end
generate_uuid() click to toggle source
# File lib/cfndk/command.rb, line 22
def generate_uuid
  puts SecureRandom.uuid
  0
end
help(command = nil, subcommand = false) click to toggle source
Calls superclass method
# File lib/cfndk/command.rb, line 13
def help(command = nil, subcommand = false)
  super(command, subcommand)
  2
end
init() click to toggle source
# File lib/cfndk/command.rb, line 34
def init
  config_path = "#{Dir.getwd}/cfndk.yml"
  if File.file?(config_path)
    CFnDK.logger.error "File exist. #{config_path}".color(:red)
    return 1
  end
  CFnDK.logger.info 'init...'.color(:green)
  FileUtils.cp_r(Dir.glob(File.dirname(__FILE__) + '/../../skel/*'), './')
  CFnDK.logger.info "create #{config_path}".color(:green)
end
invoke_command(command, *args) click to toggle source
Calls superclass method
# File lib/cfndk/command.rb, line 128
def invoke_command(command, *args)
  CFnDK.logger = CFnDKLogger.new(options)
  Rainbow.enabled = false unless options[:color]
  super
end
report() click to toggle source
# File lib/cfndk/command.rb, line 110
def report
  CFnDK.logger.info 'report...'.color(:green)

  data = load_config_data(options)
  credentials = resolve_credential(data, options)

  stacks = CFnDK::Stacks.new(data, options, credentials)
  stacks.report
  return 0
rescue => e
  CFnDK.logger.error "#{e.class}: #{e.message}".color(:red)
  e.backtrace_locations.each do |line|
    CFnDK.logger.debug line
  end
  return 1
end
version() click to toggle source
# File lib/cfndk/command.rb, line 28
def version
  puts CFnDK::VERSION
  0
end