Class: Monster::Remote::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(syncer = Sync, out = STDOUT, input = STDIN) ⇒ CLI

Returns a new instance of CLI.



8
9
10
11
12
# File 'lib/monster/remote/cli.rb', line 8

def initialize(syncer=Sync, out=STDOUT, input=STDIN)
  @syncer = syncer
  @out = out
  @in = input
end

Instance Method Details

#run(args = ARGV) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/monster/remote/cli.rb', line 14

def run(args=ARGV)
  options = parse_options(args)

  show_version if options[:show_version]
  password = nil

  config = Configuration.new
  if options[:password] || config.password_required?
    password = wait_for_password
  end

  connection_wrapper = options[:wrapper] || Monster::Remote::Wrappers::NetFTP
  local_dir = options[:local_dir] || config.local_dir || Dir.pwd
  remote_dir = options[:remote_dir] || config.remote_dir || File.basename(local_dir)
  out = (options[:verbose] || config.verbose?) ? STDOUT : nil
  host = options[:host] || config.host || "localhost"
  port = options[:port] || config.port || 21
  user = options[:user] || config.user || nil

  sync = @syncer.new(connection_wrapper, local_dir, remote_dir, out)
  sync.start(user, password, host, port)
end

#show_versionObject



37
38
39
40
# File 'lib/monster/remote/cli.rb', line 37

def show_version
  @out.puts Monster::Remote::VERSION
  exit(0)
end

#wait_for_passwordObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/monster/remote/cli.rb', line 42

def wait_for_password
  @out.print "password:"

  system("stty -echo")

  password = @in.gets.strip

  system("stty echo")
  system("echo \"\"")

  password
end