Class: ExecRemote::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/exec_remote/cli.rb

Class Method Summary collapse

Class Method Details

.configObject



6
7
8
# File 'lib/exec_remote/cli.rb', line 6

def self.config
  @@config ||= Configuration.new
end

.exec_remote(command) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/exec_remote/cli.rb', line 40

def self.exec_remote(command)
  command = command.to_s.strip
  command_to_exec = "cd #{config.my_current_project_dir_on_remote} && #{command}"
  RemoteExecutor.connect_and_execute(command_to_exec, config.remote_host, config.remote_user, config.remote_password) unless command.empty?
rescue Net::SSH::AuthenticationFailed => e
  puts "Either add your public key to server 'authorized_hosts' or provide password in the '.exec_remote.yml' file"
end

.executeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/exec_remote/cli.rb', line 10

def self.execute
  $stdout.sync = true
  begin
    puts "Exec Remote Shell"
    puts "================="
    
    rsync if config.rsync?

    puts "Enter your commands now"
    shell = Shell.new
    while(true)
      process_command shell.read_line
    end
  rescue StandardError => e
    puts "Exiting because of error: #{e}"
    raise e
  end
end

.process_command(command) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/exec_remote/cli.rb', line 29

def self.process_command(command)
  if command[0,1] == "!"
    command = command[1..-1]
    print "again "
    rsync
  end

  exit if command == "exit"
  exec_remote command
end

.rsyncObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/exec_remote/cli.rb', line 48

def self.rsync
  # FixMe: Read password from config if available
  rsync_command = ["rsync -r"]
  rsync_command << "--exclude=#{config.rsync_ignore_pattern}" if config.rsync_ignore_pattern
  rsync_command << "#{config.current_dir} #{config.remote_user}@#{config.remote_host}:#{config.my_dir_on_remote}"
  puts "rsyncing.."
  cmd = rsync_command.join(' ')
  `#{cmd}`
  puts "Done"
end