Class: OptCFBackup

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

Overview

Option parser class for CFBackup

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ OptCFBackup

Implementation of initialize

Initializes object with command line arguments passed



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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/optcfbackup.rb', line 15

def initialize(args)
  
  @banner = "Usage: cfbackup.rb --action push|pull|delete options --container CONTAINER"
  
  @options = OpenStruct.new
  self.options.config        = ["#{ENV['HOME']}/.cfconfig.yml", './cfconfig.yml', '/etc/cfconfig.yml']
  self.options.action        = ''
  self.options.pipe_data     = false
  self.options.show_ver      = false
  self.options.recursive     = false
  self.options.local_net     = false
  self.options.container     = ''
  self.options.local_path    = ''
  self.options.remote_path   = ''
  self.options.verbose       = false
  self.options.max_retries   = 3
  self.options.ignore_errors = false
  self.options.error_log     = false
  
  opts = OptionParser.new do |opts|
    opts.banner = self.banner
    
    opts.on("--action ACTION", "Action to perform: push, pull, or delete.") do |action|
      self.options.action = action
    end
    
    opts.on("--pipe_data", "Pipe data from another application and stream it to Cloud Files") do |pipe|
      self.options.pipe_data = pipe
    end
    
    opts.on("-r", "--recursive", "Traverse local path recursivley") do |recursive|
      self.options.recursive = recursive
    end
    
    opts.on("-v", "--verbose", "Run verbosely") do |verbose|
      self.options.verbose = verbose
    end
    
    opts.on("--local_path LOCAL_PATH", "Local path or file") do |local_path|
      self.options.local_path = local_path
    end
    
    opts.on("--container CONTAINER", "Cloud Files container name") do |name|
      self.options.container, self.options.remote_path = name.split(":", 2)
      clean_remote_path unless (self.options.remote_path.nil?) 
    end
    
    opts.on("--version", "Show current version") do |version|
      self.options.show_ver = version
    end
    
    opts.on("--config_file PATH", "Use specified config file, rather than the default") do |config|
      self.options.config = Array.new()
      self.options.config << config
    end
    
    opts.on("--local_net", "Use unmetered connection in DFW1 (only applicable to Slicehost or Mosso Cloud Server customers)") do |local_net|
      self.options.local_net = local_net
    end
    
    opts.on("--max_retries COUNT", "Change the number of times to retry an operation before giving up.") do |config|
      self.options.max_retries = max_retries
    end
    
    opts.on("--ignore_errors", "Ignore file operation errors (push only) and continue processing other files.") do |ignore_errors|
      self.options.ignore_errors = ignore_errors
    end
    
    opts.on("--error_log FILEPATH", "Create an error log at the given filepath containing a listing of failed push operations.") do |error_log|
      self.options.error_log = error_log
    end
    
  end
  
  opts.parse!(args) # Parse arguments
  
end

Instance Attribute Details

Ussage message



10
11
12
# File 'lib/optcfbackup.rb', line 10

def banner
  @banner
end

#optionsObject (readonly)

Options structure



9
10
11
# File 'lib/optcfbackup.rb', line 9

def options
  @options
end