Class: QuickSync::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/quicksync/cli.rb', line 6

def self.run

  $logger.debug "CLI.run: function called"
  qsync = QuickSync::RSync.new
  config = $default_options
  
  from = {}
  to = {}
  options={}
  settings = {}
  copy_strategy = :push_to;
  
  ui.choose do |menu|
    menu.prompt = "Copy strategy?  "
    copy_strategy = menu.choices(:pull_from, :push_to) 
  end
  from[:dir]      = ui.ask("from[:dir]?  ")     { |q| q.default = config[:from][:dir] }
  from[:host]     = ui.ask("from[:host]?  ")    { |q| q.default = config[:from][:host] }
  from[:user]     = ui.ask("from[:user]?  ")    { |q| q.default = config[:from][:user] }
  to[:dir]        = ui.ask("to[:dir]?  ")       { |q| q.default = config[:to][:dir] }
  to[:host]       = ui.ask("to[:host]?  ")      { |q| q.default = config[:to][:host] }
  to[:user]       = ui.ask("to[:user]?  ")      { |q| q.default = config[:to][:user] }
  options[:include]       = ui.ask("includes?  ", lambda { |str| str.split(/,\s*/) })      { |q| q.default = config[:include].join(',')}
  options[:exclude]       = ui.ask("excludes?  ", lambda { |str| str.split(/,\s*/) })    { |q| q.default = config[:exclude].join(',') }
  options[:copy_options]  = ui.ask("copy options?  ", lambda { |str| str.split(/,\s*/) })  { |q| q.default = config[:copy_options].join(',') }
  
  config[:settings].each do |key, value|
    settings[key.to_sym] = ui.ask("settings[#{key.to_s}]?  ") { |q| q.default = "#{value}" }
  end
  options[:settings] = settings

  $logger.debug "CLI.run from=#{from}"
  $logger.debug "CLI.run to=#{to}"
  $logger.debug "CLI.run copy_options=#{options[:copy_options]}"
  $logger.debug "CLI.run include=#{options[:include]}"
  $logger.debug "CLI.run exclude=#{options[:exclude]}"
  $logger.debug "CLI.run settings=#{options[:settings]}"
  
  qs = QuickSync::RSync.new
  cmd = qs.pull_from(from,to,options)
  $logger.important "CLI.run: pull_from cmd=#{cmd}"
  
  

end

.uiObject



52
53
54
# File 'lib/quicksync/cli.rb', line 52

def self.ui
  @ui ||= HighLine.new
end

Instance Method Details

#env_var(var) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/quicksync/cli.rb', line 56

def env_var(var)
  if ! ENV[var].nil? && ! ENV[var].empty?
    return ENV[var]
  else
    return ""
  end
end

#env_var_bool(var) ⇒ Object



64
65
66
# File 'lib/quicksync/cli.rb', line 64

def env_var_bool(var)
  return to_boolean(ENV[var])
end