Sha256: 2dabe61cd036a7abc1d9275385f1c0de3618062e9904574c00066ef85bf9dde8

Contents?: true

Size: 806 Bytes

Versions: 1

Compression:

Stored size: 806 Bytes

Contents

class Freighthop::CLI::SSH
  def self.match?(*args)
    !args.empty? # we handle guest passthrough
  end

  def initialize(*args)
    @args = args
  end

  def run
    Freighthop::CLI::Checks.ensure_config_exists!
    if shell?
      ssh('-i')
    else
      ssh(%Q(-c "#{@args.join(' ')}"))
    end
  end

  def shell?
    @args.first == 'ssh'
  end

  def ssh(cmd)
    exec %Q(ssh -q -t -F #{config} #{app_name} 'cd #{guest_root}; /bin/bash -l #{cmd}')
  end

  def config
    config_path.tap do |conf|
      if !conf.exist? || (Time.now - conf.mtime) > 86400
        `vagrant ssh-config > #{conf}`
      end
    end
  end

  def config_path
    Pathname("/tmp/freighthop.#{app_name}.ssh-config")
  end

  def app_name
    Freighthop.app_name
  end

  def guest_root
    Freighthop.guest_root
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
freighthop-0.4.1 lib/freighthop/cli/ssh.rb