diff --git a/lib/giddyup/command_wrapper.rb b/lib/giddyup/command_wrapper.rb index 1c423af..97584d6 100644 --- a/lib/giddyup/command_wrapper.rb +++ b/lib/giddyup/command_wrapper.rb @@ -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: `` and ``. + # def self.run_command(cmd) output = [] rv = nil @@ -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 @@ -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 diff --git a/lib/giddyup/git_deploy.rb b/lib/giddyup/git_deploy.rb index 6f83355..836a9f1 100644 --- a/lib/giddyup/git_deploy.rb +++ b/lib/giddyup/git_deploy.rb @@ -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 @@ -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