class Humidifier::Reservoir::CLI

A CLI for running commands to manipulate the stacks that Reservoir knows about.

Public Instance Methods

authorize() click to toggle source
# File lib/humidifier/reservoir/cli.rb, line 73
def authorize
  return unless options[:aws_profile]
  Aws.config[:credentials] =
    Aws::SharedCredentials.new(profile_name: options[:aws_profile])
end
change(name = nil) click to toggle source
# File lib/humidifier/reservoir/cli.rb, line 13
def change(name = nil)
  stack_names = stack_names_from(name)
  authorize

  stack_names.each do |stack_name|
    stack = Stack.new(stack_name)
    puts "Creating a changeset for #{stack.stack_name}"
    stack.create_change_set
  end
end
deploy(name = nil, *parameters) click to toggle source
# File lib/humidifier/reservoir/cli.rb, line 28
def deploy(name = nil, *parameters)
  stack_names = stack_names_from(name)
  authorize

  stack_names.each do |stack_name|
    stack = Stack.new(stack_name, prefix: options[:prefix])
    puts "Deploying #{stack.stack_name}"
    stack.deploy(options[:wait], parameters_from(parameters))
  end
end
display(name, pattern = nil) click to toggle source
# File lib/humidifier/reservoir/cli.rb, line 41
def display(name, pattern = nil)
  puts Stack.new(name, pattern: pattern && /#{pattern}/i).to_cf
end
parameters_from(opts) click to toggle source
# File lib/humidifier/reservoir/cli.rb, line 79
def parameters_from(opts)
  opts.map do |opt|
    key, value = opt.split('=')
    { parameter_key: key, parameter_value: value }
  end
end
safe_execute() { || ... } click to toggle source
# File lib/humidifier/reservoir/cli.rb, line 86
def safe_execute
  yield
rescue Error => error
  raise error if options[:debug]
  puts error.message
  exit 1
end
stack_names_from(name) click to toggle source
# File lib/humidifier/reservoir/cli.rb, line 94
def stack_names_from(name)
  name ? [name] : Reservoir.stacks
end
upload(name = nil) click to toggle source
# File lib/humidifier/reservoir/cli.rb, line 46
def upload(name = nil)
  stack_names = stack_names_from(name)
  authorize

  stack_names.each do |stack_name|
    stack = Stack.new(stack_name)
    puts "Uploading #{stack.stack_name}"
    stack.upload
  end
end
validate(name = nil) click to toggle source
# File lib/humidifier/reservoir/cli.rb, line 59
def validate(name = nil)
  stack_names = stack_names_from(name)
  authorize

  print 'Validating... '

  if stack_names.all? { |stack_name| Stack.new(stack_name).valid? }
    puts 'Valid.'
  else
    puts 'Invalid.'
  end
end