Sha256: 621f51dfb1240fe4e6c30318413cc28086f54baf3d778a8cbcfb42bdee27cd02

Contents?: true

Size: 968 Bytes

Versions: 3

Compression:

Stored size: 968 Bytes

Contents

require 'escape'

module Wordmove
  class LocalHost

    attr_reader :options
    attr_reader :logger
    attr_reader :ssh_extras

    def initialize(options = {})
      @options = Hashie::Mash.new(options)
      @logger = @options[:logger]
      @ssh_extras = {}
      [ :port, :password ].each do |p|
        @ssh_extras.merge!( { p => @options.ssh[p] } ) if @options.ssh and @options.ssh[p]
      end
    end

    def run(*args)
      command = shell_command(*args)
      logger.verbose "Executing locally #{command}"
      unless system(command)
        raise Thor::Error, "Error executing \"#{command}\""
      end
    end

    def close
    end

    protected

    def shell_command(*args)
      options = args.extract_options!
      command = Escape.shell_command(args)
      if options[:stdin]
        command += " < #{options[:stdin]}"
      end
      if options[:stdout]
        command += " > #{options[:stdout]}"
      end
      command
    end

  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
wordmove-0.0.7 lib/wordmove/hosts/local_host.rb
wordmove-0.0.6 lib/wordmove/hosts/local_host.rb
wordmove-sshbump-0.0.8 lib/wordmove/hosts/local_host.rb