Class: PgMigrate::CommandLine

Inherits:
Thor
  • Object
show all
Defined in:
lib/pg_migrate/command_line.rb

Constant Summary collapse

@@packaged_source =
'.'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CommandLine

Returns a new instance of CommandLine.



6
7
8
# File 'lib/pg_migrate/command_line.rb', line 6

def initialize(*args)
  super
end

Class Method Details

.packaged_sourceObject



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

def self.packaged_source
  @@packaged_source
end

.packaged_source=(value) ⇒ Object



14
15
16
# File 'lib/pg_migrate/command_line.rb', line 14

def self.packaged_source=(value)
  @@packaged_source = value
end

Instance Method Details

#buildObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/pg_migrate/command_line.rb', line 82

def build
  source = options[:source]

  if source.nil?
    source = @@packaged_source
  end

  method_defaults = {"force" => false, "verbose" => false}
  local_options = set_defaults_from_file(method_defaults, "build", source)
  local_options = local_options.merge(options)

  bootstrap_logger(local_options["verbose"])

  if !local_options["out"]
    puts "error: --out not specified"
    exit 1
  end

  manifest_reader = ManifestReader.new
  sql_reader = SqlReader.new
  builder = Builder.new(manifest_reader, sql_reader)
  builder.build(source, local_options["out"], :force => local_options["force"])
end

#downObject



68
69
70
71
72
73
74
# File 'lib/pg_migrate/command_line.rb', line 68

def down
  local_options = options
  options = set_defaults_from_file(location_options)
  bootstrap_logger(options[:verbose])

  raise 'Not implemented'
end

#packageObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pg_migrate/command_line.rb', line 115

def package
  source = options[:source]

  if source.nil?
    source = @@packaged_source
  end

  method_defaults = {"force" => false, "verbose" => false}
  local_options = set_defaults_from_file(method_defaults, "package", source)
  local_options = local_options.merge(options)

  if !local_options["out"]
    puts "error: --out not specified"
    exit 1
  end
  if !local_options["name"]
    puts "error: --version not specified"
    exit 1
  end
  if !local_options["version"]
    puts "error: --version not specified"
    exit 1
  end

  bootstrap_logger(local_options["verbose"])

  manifest_reader = ManifestReader.new
  builder = Package.new(manifest_reader)
  builder.package(source, local_options["out"], local_options["name"], local_options["version"], :force => local_options["force"])
end

#upObject



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
# File 'lib/pg_migrate/command_line.rb', line 24

def up
  source = options[:source]

  if source.nil?
    source = @@packaged_source
  end

  method_defaults = {"verbose" => false}
  local_options = set_defaults_from_file(method_defaults, "up", source)
  local_options = local_options.merge(options)

  bootstrap_logger(local_options["verbose"])

  manifest_reader = ManifestReader.new
  sql_reader = SqlReader.new

  connopts = local_options["connopts"]
  if !connopts["port"].nil?
    connopts[:port] = connopts[:port].to_i
  end

  migrator = Migrator.new(manifest_reader, sql_reader, connopts)

  begin
    migrator.migrate(source)
  rescue Exception => e
    if !local_options["verbose"]
      # catch common exceptions and make pretty on command-line
      if !e.message.index("ManifestReader: code=unloadable_manifest").nil?
        puts "Unable to load manifest in source directory '#{source}' .  Check -s|--source option and run again."
        exit 1
      else
        raise e
      end
    else
      raise e
    end
  end


end