Class: CouchReplicate::CommandLine
- Inherits:
-
Object
- Object
- CouchReplicate::CommandLine
- Defined in:
- lib/couch_replicate/command_line.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #parse_options(args) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ CommandLine
Returns a new instance of CommandLine.
12 13 14 |
# File 'lib/couch_replicate/command_line.rb', line 12 def initialize(args) (args) end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
10 11 12 |
# File 'lib/couch_replicate/command_line.rb', line 10 def database @database end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
10 11 12 |
# File 'lib/couch_replicate/command_line.rb', line 10 def hosts @hosts end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/couch_replicate/command_line.rb', line 10 def @options end |
Class Method Details
.run(*args) ⇒ Object
6 7 8 |
# File 'lib/couch_replicate/command_line.rb', line 6 def self.run(*args) CommandLine.new(*args).run end |
Instance Method Details
#parse_options(args) ⇒ Object
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 |
# File 'lib/couch_replicate/command_line.rb', line 31 def (args) @options = { } = OptionParser.new do |opts| opts. = "Usage: couch-replicate db [OPTIONS] couchdb_host_01, couchdb_host_02[, couchdb_host_03...]" opts.separator "" opts.on("-l", "--link", "link the hosts in a circular list (this is the default if no other options are specified)") do @options[:link] = true end opts.on("-r", "--reverse", "link the hosts in a cicular list, reversing the order supplied") do @options[:reverse] = true end opts.on("-n", "-number [LINK_EVERY=3]", "link every n hosts") do |n| @options[:n] = n.to_i > 0 ? n.to_i : 3 end opts.separator "" opts.on_tail("-v", "--version", "Show version") do puts File.basename($0) + " " + CouchReplicate.version exit end # No argument, shows at tail. This will print an options summary. # Try it and see! opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end begin .parse!(args) @database = args.shift @hosts = args if @options[:n] && (@options[:n] == @hosts.length + 1) raise OptionParser::InvalidOption.new("The number of hosts cannot equal the replication shift.") end rescue OptionParser::InvalidOption => e raise e end end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/couch_replicate/command_line.rb', line 16 def run if @options[:link] || @options.empty? $stderr.puts "Linking replication hosts..." CouchReplicate.link(@database, @hosts) end if @options[:reverse] $stderr.puts "Reverse linking replication hosts..." CouchReplicate.reverse_link(@database, @hosts) end if @options[:n] $stderr.puts "Linking every #{@options[:n]}th replication hosts..." CouchReplicate.nth(@options[:n], @database, @hosts) end end |