Skip to content

Commit

Permalink
Print output in real-time with -v
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalmer committed Jan 5, 2015
1 parent d3ce7b8 commit 7841cbf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 9 additions & 2 deletions lib/giddyup/command_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def initialize(status, output, command)
# Giddyup::CommandWrapper::CommandFailed exception is raised containing
# the status of the failed command and all output.
#
# If a block is passed, it will be called for each line of output, and
# pass two arguments: `<stream>` and `<line>`.
#
def self.run_command(cmd)
output = []
rv = nil
Expand Down Expand Up @@ -70,7 +73,9 @@ def self.run_command(cmd)
stdout.close
fds.delete(stdout)
else
output << [:stdout, stdout.readline.chomp]
l = stdout.readline.chomp
yield :stdout, l if block_given?
output << [:stdout, l]
end
end

Expand All @@ -79,7 +84,9 @@ def self.run_command(cmd)
stderr.close
fds.delete(stderr)
else
output << [:stderr, stderr.readline.chomp]
l = stderr.readline.chomp
yield :stderr, l if block_given?
output << [:stderr, l]
end
end
end
Expand Down
12 changes: 9 additions & 3 deletions lib/giddyup/git_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,18 @@ def config_list(regex)
# as a string.
#
def run_command(desc, cmdline)
@stdout.print "[....] #{desc}"
in_progress = "[....] #{desc}"

$stdout.print in_progress

output = nil
failed = false
begin
output = @command.run_command(cmdline)
output = @command.run_command(cmdline) do |fd, l|
next unless @verbose
@stdout.puts "\x0d\x1b[K#{fd.to_s.send(fd == :stderr ? :cyan : purple)}: #{l}"
@stdout.print in_progress
end
rescue Giddyup::CommandWrapper::CommandFailed => e
@stdout.puts "\x0d["+"FAIL".red+"] #{desc}"
output = e.output
Expand All @@ -199,7 +205,7 @@ def run_command(desc, cmdline)
@stdout.puts "\x0d["+" OK ".green+"] #{desc}"
end

if @verbose or failed
if failed and !@verbose
@stdout.puts cmdline
@stdout.puts output.map { |l| "#{l[0].to_s.send(l[0] == :stderr ? :cyan : :purple)}: #{l[1]}" }.join("\n")
end
Expand Down

0 comments on commit 7841cbf

Please sign in to comment.