lib/bard/base.rb in bard-0.53.0 vs lib/bard/base.rb in bard-0.54.0

- old
+ new

@@ -6,22 +6,28 @@ class Bard::CLI < Thor include Term::ANSIColor private - def run_crucial(command, verbose = false) - stdout, stderr, status = Open3.capture3(command) - failed = status.to_i.nonzero? - if verbose || failed - $stdout.puts stdout - $stderr.puts stderr + def run_crucial command, verbose: false + failed = false + + if verbose + failed = !(system command) + else + stdout, stderr, status = Open3.capture3(command) + failed = status.to_i.nonzero? + if failed + $stdout.puts stdout + $stderr.puts stderr + end end + if failed puts red("!!! ") + "Running command failed: #{yellow(command)}" exit 1 end - stdout.chomp end def project_name @project_name ||= File.expand_path(".").split("/").last end @@ -38,11 +44,11 @@ command = "ssh -tt #{" -p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} \"#{command}\"" end command end - def copy direction, server, path + def copy direction, server, path, verbose: false server = @config.servers[server.to_sym] uri = URI.parse("ssh://#{server.gateway}") port = uri.port ? "-p#{uri.port}" : "" gateway = server.gateway ? "-oProxyCommand='ssh #{port} #{uri.user}@#{uri.host} -W %h:%p'" : "" @@ -54,14 +60,14 @@ from_and_to = [path, "#{uri.user}@#{uri.host}:#{server.path}/#{path}"] from_and_to.reverse! if direction == :from command = "scp #{gateway} #{ssh_key} #{port} #{from_and_to.join(" ")}" - run_crucial command + run_crucial command, verbose: verbose end - def rsync direction, server, path + def rsync direction, server, path, verbose: false server = @config.servers[server.to_sym] uri = URI.parse("ssh://#{server.gateway}") port = uri.port ? "-p#{uri.port}" : "" gateway = server.gateway ? "-oProxyCommand=\"ssh #{port} #{uri.user}@#{uri.host} -W %h:%p\"" : "" @@ -75,11 +81,11 @@ dest_path = "./#{dest_path}" from_and_to = [dest_path, "#{uri.user}@#{uri.host}:#{server.path}/#{path}"] from_and_to.reverse! if direction == :from from_and_to[-1].sub! %r(/[^/]+$), '/' - command = "rsync #{ssh} --delete -avz #{from_and_to.join(" ")}" + command = "rsync #{ssh} --delete --info=progress2 -az #{from_and_to.join(" ")}" - run_crucial command + run_crucial command, verbose: verbose end end