lib/bard/remote_command.rb in bard-0.67.0 vs lib/bard/remote_command.rb in bard-0.68.0

- old
+ new

@@ -1,7 +1,11 @@ module Bard class RemoteCommand < Struct.new(:server, :command, :home) + def self.run! *args + new(*args).run! + end + def local_command uri = URI.parse("ssh://#{server.ssh}") ssh_key = server.ssh_key ? "-i #{server.ssh_key} " : "" cmd = command if server.env @@ -14,9 +18,28 @@ if server.gateway uri = URI.parse("ssh://#{server.gateway}") cmd = "ssh -tt #{" -p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} \"#{cmd}\"" end cmd + end + + def run! verbose: false + failed = false + + if verbose + failed = !(system local_command) + else + stdout, stderr, status = Open3.capture3(local_command) + failed = status.to_i.nonzero? + if failed + $stdout.puts stdout + $stderr.puts stderr + end + end + + if failed + raise "Running command failed: #{local_command}" + end end end end