Sha256: 5cd30a0a1da7ce38393079f115c4bf25e76db4688c2878f42d3d77416102a2da

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require 'mattock/command-task'
module Mattock
  class RemoteCommandTask < CommandTask
    runtime_setting(:remote_server, nested(
      :address => nil,
      :user => nil
    ))
    setting(:ssh_options, [])
    nil_fields(:id_file, :free_arguments)
    runtime_setting(:remote_target)

    def resolve_runtime_configuration
      super
      self.remote_target ||= [remote_server.user, remote_server.address].compact.join('@') unless remote_server.address.nil?
    end

    def ssh_option(name, value)
      ssh_options << "\"#{name}=#{value}\""
    end

    def decorated(command_on_remote)
      fail "Need remote server for #{self.class.name}" unless remote_server.address

      raise "Empty remote command" if command_on_remote.nil?
      Mattock::WrappingChain.new do |cmd|
        cmd.add Mattock::CommandLine.new("ssh") do |cmd|
          cmd.options << "-i #{id_file}" if id_file
          unless ssh_options.empty?
            ssh_options.each do |opt|
              cmd.options << "-o #{opt}"
            end
          end
          cmd.options << remote_target
        end
        cmd.add Mattock::ShellEscaped.new(command_on_remote)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mattock-0.3.4 lib/mattock/remote-command-task.rb
mattock-0.3.3 lib/mattock/remote-command-task.rb
mattock-0.3.2 lib/mattock/remote-command-task.rb
mattock-0.3.1 lib/mattock/remote-command-task.rb