module RatDeployer::Command
Rat::Deployer encapsulates all code related to running a shell command and displaying it's output.
Public Instance Methods
colorize_warning(str)
click to toggle source
# File lib/rat_deployer/command.rb, line 52 def colorize_warning(str) "\\\\ #{str}".colorize(:yellow) end
do_run(cmd, silent: false)
click to toggle source
# File lib/rat_deployer/command.rb, line 21 def do_run(cmd, silent: false) output = '' status = 1 IO.popen(ENV, cmd) do |io| while line = io.gets # rubocop:disable Lint/AssignmentInCondition puts line unless silent output << line end io.close status = $CHILD_STATUS.to_i end { output: output, status: status } end
put_error(str)
click to toggle source
# File lib/rat_deployer/command.rb, line 42 def put_error(str) return unless RatDeployer::Config.prompt_enabled? puts "// #{str}".colorize(:red) end
put_heading(str)
click to toggle source
# File lib/rat_deployer/command.rb, line 37 def put_heading(str) return unless RatDeployer::Config.prompt_enabled? puts "|| #{str}".colorize(:blue) end
put_warning(str)
click to toggle source
# File lib/rat_deployer/command.rb, line 47 def put_warning(str) return unless RatDeployer::Config.prompt_enabled? puts colorize_warning(str) end
run(cmd, silent: false)
click to toggle source
# File lib/rat_deployer/command.rb, line 10 def run(cmd, silent: false) if !silent && RatDeployer::Config.prompt_enabled? puts '||=> Running command '.colorize(:blue) + "`#{cmd.colorize(:white)}`" end command = do_run(cmd, silent: silent) exit 1 unless command.fetch(:status).zero? command end