Sha256: 752d3177e94bfacc31dd66df43448fa1387d9c423e97fbb679ab2e73cb20d2a1

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Mina
  module Backend
    class Remote
      attr_reader :commands, :configuration

      extend Forwardable
      def_delegators :configuration, :fetch, :set?

      def initialize(commands)
        @configuration = Mina::Configuration.instance
        @commands = commands
      end

      def prepare
        if fetch(:simulate)
          [
            '#!/usr/bin/env bash', "# Executing the following via '#{ssh}':",
            '#', commands, ' '
          ].join("\n")
        else
          command = Shellwords.escape(commands)
          [ssh, '--', command].join(' ')
        end
      end

      private

      def ssh
        fail 'No domain set' unless set?(:domain)
        args = fetch(:domain)
        args = "#{fetch(:user)}@#{fetch(:domain)}" if set?(:user)
        args << " -i #{fetch(:identity_file)}" if set?(:identity_file)
        args << " -p #{fetch(:port)}" if set?(:port)
        args << ' -A' if set?(:forward_agent)
        args << " #{fetch(:ssh_options)}" if set?(:ssh_options)
        args << ' -tt'
        "ssh #{args}"
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mina-1.0.0.beta1 lib/mina/backend/remote.rb