Module: BbDeploy::Task

Defined in:
lib/bb_deploy/task.rb

Class Method Summary collapse

Class Method Details

.ask(prompt, required_response: 'yes', important: false) ⇒ Object



18
19
20
21
22
23
24
25
26
# 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) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 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