lib/shexy.rb in shexy-0.1 vs lib/shexy.rb in shexy-0.2

- old
+ new

@@ -30,19 +30,19 @@ # # Shexy.copy_to 'test@test-host', '/home/rubiojr/my-uber-file', '/tmp/' # module Shexy - VERSION = '0.1' + VERSION = '0.2' @flags = {} def self.password=(password); flags[:password] = password; end def self.password; flags[:password]; end def self.key=(key); flags[:keys] = [File.expand_path(key)]; end def self.key; flags[:keys]; end - def self.use_sudo; @sudo = true; end + def self.use_sudo(v=true); @sudo = v; end def self.sudo?; @sudo ||= false; end class << self attr_accessor :host, :user, :flags attr_reader :cmd @@ -68,22 +68,30 @@ ch.exec cmd do # FIXME: I don't think it's a good idea # to implement access to stdout,stderr this way stdout = "" stderr = "" + exit_code = -1 + exit_signal = -1 ch.on_extended_data do |c2, type, data| # ERROR output here stderr << data - yield stdout, stderr if block_given? + yield nil, data if block_given? end ch.on_data do |c2, data| stdout << data - yield stdout, stderr if block_given? + yield data, nil if block_given? end ch.on_close do |c2| - return stdout, stderr + return stdout, stderr, exit_code, exit_signal end + ch.on_request("exit-status") do |c2,data| + exit_code = data.read_long + end + ch.on_request("exit-signal") do |c2, data| + exit_signal = data.read_long + end end end end end @@ -95,10 +103,16 @@ # Shexy.host = 'foobar.com' # Shexy.user = 'root' # Shexy.copy_to 'source_file', 'dest_file' # def self.copy_to(*args) + opts = {} + if args.include?(:recursive) + opts = { :recursive => true } + args.delete :recursive + end + if args.size > 2 # First arg assumed to be foo@host.net @host = args[0] if @host =~ /@/ @user, @host = @host.split '@' @@ -111,10 +125,10 @@ from = args[0] to = args[1] end from = File.expand_path from Net::SCP.start(host, user, flags) do |scp| - scp.upload! from, to + scp.upload! from, to, opts end end # # Detect distro version