module BbDeploy::Task

Public Class Methods

ask(prompt, required_response: 'yes', important: false) click to toggle source
# File lib/bb_deploy/task.rb, line 18
def ask(prompt, required_response: 'yes', important: false)
  msg = prompt + "\n\nTyping anything other than '#{required_response}' will abort."
  if important # Color important text RED and highlight the required response
    msg = "\e[31m#{msg}\e[0m"
    msg.sub!(/'#{required_response}'/, "\e[47m'#{required_response}'\e[49m")
  end
  puts
  HighLine.new.ask(msg) =~ /\A#{required_response}\Z/i
end
run(*cmds) click to toggle source
# File lib/bb_deploy/task.rb, line 3
def run(*cmds)
  dry_run = !!ENV['DRY_RUN']
  Dir.chdir(Rails.root)
  result = cmds.map do |cmd|
    cmd_s = "==> \`#{cmd}\`"
    if dry_run
      puts "DRY RUN ONLY"
      puts cmd_s
    else
      with_timing(cmd_s) { `#{cmd}` || raise("System call failed: #{cmd.inspect}") }
    end
  end
  result.last.try(:strip) unless dry_run
end

Private Class Methods

with_timing(what) { || ... } click to toggle source
# File lib/bb_deploy/task.rb, line 30
def with_timing(what)
  start = Time.current
  puts
  puts "Commencing #{what} ..."
  result = yield
  time = Time.zone.at(Time.current - start).getutc.strftime("%H:%M:%S")
  puts "Finished #{what} in #{time}."
  puts
  result
end