class Stackit::BaseCli

Public Class Methods

banner(task, namespace = true, subcommand = false) click to toggle source
exit_on_failure?() click to toggle source
# File lib/stackit/cli/base_cli.rb, line 27
def self.exit_on_failure?
  true
end
new(*args) click to toggle source
Calls superclass method
# File lib/stackit/cli/base_cli.rb, line 14
def initialize(*args)
  super(*args)
  init_cli
end
subcommand_prefix() click to toggle source
# File lib/stackit/cli/base_cli.rb, line 23
def self.subcommand_prefix
  self.name.gsub(%r{.*::}, '').gsub(%r{^[A-Z]}) { |match| match[0].downcase }.gsub(%r{[A-Z]}) { |match| "-#{match[0].downcase}" }
end

Public Instance Methods

init_cli() click to toggle source
# File lib/stackit/cli/base_cli.rb, line 33
def init_cli
  Stackit.debug = !!options[:debug]
  Stackit.environment = options[:environment].to_sym

  if Stackit.debug
    Stackit.logger.level = Logger::DEBUG
    Stackit.logger.debug "Initializing CLI in DEBUG mode!"
    begin
      require 'pry-byebug'
    rescue LoadError; end
  elsif options[:verbose]
    Stackit.logger.level = Logger::INFO
    Stackit.logger.debug "Initializing CLI with INFO logging level"
  else
    Stackit.logger.level = Logger::ERROR
  end

  Stackit.logger.debug "Environment: #{Stackit.environment}"

  Stackit.aws.credentials = Stackit.aws.load_credentials(options[:environment])

  Stackit.aws.profile = options[:profile] if options[:profile]
  Stackit.logger.debug "Profile: #{Stackit.aws.profile}"

  Stackit.aws.region = options[:region] if options[:region]
  Stackit.logger.debug "Region: #{Stackit.aws.region}"

  if options[:assume_role] && options[:assume_role].has_key?('name')
    name = options[:assume_role]['name']
    duration = options[:assume_role].has_key?('duration') ? options[:assume_role]['duration'] : 3600
    Stackit.aws.assume_role!(name, duration)
    Stackit.logger.debug "Assumed Role: #{name}"
  end
end