Sha256: fe3c1e62f82191f8f7eaed93c37552da9a89894ea727fbe55fa5a56cb04af52b

Contents?: true

Size: 1.03 KB

Versions: 9

Compression:

Stored size: 1.03 KB

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

      puts "SSH options: #{@ssh_extras.inspect}"
    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!
      puts "Commands: #{args.inspect}"
      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

9 entries across 9 versions & 1 rubygems

Version Path
wordmove-sshbump-0.2.2 lib/wordmove/hosts/local_host.rb
wordmove-sshbump-0.2.1 lib/wordmove/hosts/local_host.rb
wordmove-sshbump-0.2.0 lib/wordmove/hosts/local_host.rb
wordmove-sshbump-0.1.9 lib/wordmove/hosts/local_host.rb
wordmove-sshbump-0.1.8 lib/wordmove/hosts/local_host.rb
wordmove-sshbump-0.1.7 lib/wordmove/hosts/local_host.rb
wordmove-sshbump-0.1.6 lib/wordmove/hosts/local_host.rb
wordmove-sshbump-0.1.5 lib/wordmove/hosts/local_host.rb
wordmove-sshbump-0.1.4 lib/wordmove/hosts/local_host.rb