class Bard::Command
Public Class Methods
exec!(command, on: :local, home: false)
click to toggle source
# File lib/bard/command.rb, line 15 def self.exec! command, on: :local, home: false new(command, on, home).exec! end
run(command, on: :local, home: false, verbose: false, quiet: false)
click to toggle source
# File lib/bard/command.rb, line 11 def self.run command, on: :local, home: false, verbose: false, quiet: false new(command, on, home).run verbose:, quiet: end
run!(command, on: :local, home: false, verbose: false, quiet: false)
click to toggle source
# File lib/bard/command.rb, line 7 def self.run! command, on: :local, home: false, verbose: false, quiet: false new(command, on, home).run! verbose:, quiet: end
Public Instance Methods
exec!()
click to toggle source
# File lib/bard/command.rb, line 39 def exec! exec full_command end
run(verbose: false, quiet: false)
click to toggle source
# File lib/bard/command.rb, line 25 def run verbose: false, quiet: false if verbose system full_command(quiet: quiet) else stdout, stderr, status = Open3.capture3(full_command) failed = status.to_i.nonzero? if failed && !quiet $stdout.puts stdout $stderr.puts stderr end !failed && stdout end end
run!(verbose: false, quiet: false)
click to toggle source
# File lib/bard/command.rb, line 19 def run! verbose: false, quiet: false if !run(verbose:, quiet:) raise Error.new(full_command) end end
Private Instance Methods
full_command(quiet: false)
click to toggle source
# File lib/bard/command.rb, line 45 def full_command quiet: false if on.to_sym == :local command else remote_command quiet: false end end
remote_command(quiet: false)
click to toggle source
# File lib/bard/command.rb, line 53 def remote_command quiet: false cmd = command if on.env cmd = "#{on.env} #{command}" end unless home cmd = "cd #{on.path} && #{cmd}" end ssh_key = on.ssh_key ? "-i #{on.ssh_key} " : "" cmd = "ssh -tt #{ssh_key} #{on.ssh_uri} '#{cmd}'" if on.gateway cmd = "ssh -tt #{on.ssh_uri(:gateway)} \"#{cmd}\"" end cmd += " 2>&1" if quiet cmd end