class Humidifier::CLI

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

Public Instance Methods

authorize() click to toggle source
# File lib/humidifier/cli.rb, line 83
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/cli.rb, line 14
def change(name = nil)
  authorize

  stack_names_from(name).each do |stack_name|
    directory = Directory.new(stack_name)

    puts "🛠 Creating a changeset for #{directory.stack_name}"
    directory.create_change_set
  end
end
deploy(name = nil, *parameters) click to toggle source
# File lib/humidifier/cli.rb, line 29
def deploy(name = nil, *parameters)
  authorize

  stack_names_from(name).each do |stack_name|
    directory = Directory.new(stack_name, prefix: options[:prefix])

    puts "🚀 Deploying #{directory.stack_name}"
    directory.deploy(options[:wait], parameters_from(parameters))
  end
end
display(name, pattern = nil) click to toggle source
# File lib/humidifier/cli.rb, line 42
def display(name, pattern = nil)
  directory = Directory.new(name, pattern: pattern && /#{pattern}/i)

  puts "📄 Displaying #{directory.stack_name}"
  puts directory.to_cf
end
parameters_from(opts) click to toggle source
# File lib/humidifier/cli.rb, line 90
def parameters_from(opts)
  opts.map do |opt|
    key, value = opt.split('=')
    { parameter_key: key, parameter_value: value }
  end
end
prelude() click to toggle source
# File lib/humidifier/cli.rb, line 97
def prelude
  command = @_invocations.values.dig(0, 0)
  command = command ? "#{command} " : ''
  puts "\033[1mhumidifier #{command}v#{VERSION}\033[0m"
end
safe_execute() { || ... } click to toggle source
# File lib/humidifier/cli.rb, line 103
def safe_execute
  prelude
  start = Time.now.to_f
  yield
rescue Error => error
  raise error if options[:debug]

  puts error.message
  exit 1
else
  puts '✨ Done in %.2fs.' % (Time.now.to_f - start)
end
stack_names_from(name) click to toggle source
# File lib/humidifier/cli.rb, line 116
def stack_names_from(name)
  name ? [name] : Humidifier.config.stack_names
end
stacks() click to toggle source
# File lib/humidifier/cli.rb, line 50
def stacks
  puts '🗒  Listing stacks'
  puts Humidifier.config.stack_names.sort.map { |name| "- #{name}" }
end
upload(name = nil) click to toggle source
# File lib/humidifier/cli.rb, line 56
def upload(name = nil)
  authorize

  stack_names_from(name).each do |stack_name|
    directory = Directory.new(stack_name)

    puts "📬 Uploading #{directory.stack_name}"
    directory.upload
  end
end
validate(name = nil) click to toggle source
# File lib/humidifier/cli.rb, line 69
def validate(name = nil)
  authorize

  print '🔍 Validating... '

  valid =
    stack_names_from(name).all? do |stack_name|
      Directory.new(stack_name).valid?
    end

  puts valid ? 'Valid.' : 'Invalid.'
end