Class: PgSync::Client

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/pgsync/client.rb

Constant Summary

Constants included from Utils

Utils::COLOR_CODES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#colorize, #confirm_tables_exist, #db_config_file, #deprecated, #escape, #first_schema, #friendly_name, #log, #monotonic_time, #output, #quote_ident, #quote_ident_full, #quote_string, #task_name, #warning

Constructor Details

#initialize(args) ⇒ Client

Returns a new instance of Client.



5
6
7
8
# File 'lib/pgsync/client.rb', line 5

def initialize(args)
  @args = args
  output.sync = true
end

Class Method Details

.startObject



34
35
36
# File 'lib/pgsync/client.rb', line 34

def self.start
  new(ARGV).perform
end

Instance Method Details

#performObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pgsync/client.rb', line 10

def perform
  result = Slop::Parser.new(slop_options).parse(@args)
  arguments = result.arguments
  options = result.to_h
  options[:defer_constraints_v2] ||= options[:defer_constraints]

  raise Error, "Specify either --db or --config, not both" if options[:db] && options[:config]
  raise Error, "Cannot use --overwrite with --in-batches" if options[:overwrite] && options[:in_batches]

  if options[:version]
    log VERSION
  elsif options[:help]
    log slop_options
  elsif options[:init]
    Init.new(arguments, options).perform
  else
    Sync.new(arguments, options).perform
  end
rescue => e
  # Error, PG::ConnectionBad, Slop::Error
  raise e if options && options[:debug]
  abort colorize(e.message.strip, :red)
end