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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/taps/cli.rb', line 118
def clientoptparse(cmd)
opts = { default_chunksize: 1000, database_url: nil, remote_url: nil, debug: false, resume_filename: nil, disable_compresion: false, indexes_first: false }
OptionParser.new do |o|
o.banner = "Usage: #{File.basename($PROGRAM_NAME)} #{cmd} [OPTIONS] <local_database_url> <remote_url>"
case cmd
when :pull
o.define_head 'Pull a database from a taps server'
when :push
o.define_head 'Push a database to a taps server'
end
o.on('-s', '--skip-schema', "Don't transfer the schema, just data") { |_v| opts[:skip_schema] = true }
o.on('-i', '--indexes-first', 'Transfer indexes first before data') { |_v| opts[:indexes_first] = true }
o.on('-r', '--resume=file', 'Resume a Taps Session from a stored file') { |v| opts[:resume_filename] = v }
o.on('-c', '--chunksize=N', 'Initial Chunksize') { |v| opts[:default_chunksize] = (v.to_i < 10 ? 10 : v.to_i) }
o.on('-g', '--disable-compression', 'Disable Compression') { |_v| opts[:disable_compression] = true }
o.on('-f', '--filter=regex', 'Regex Filter for tables') { |v| opts[:table_filter] = v }
o.on('-t', '--tables=A,B,C', Array, 'Shortcut to filter on a list of tables') do |v|
r_tables = v.collect { |t| "^#{t}$" }.join('|')
opts[:table_filter] = "(#{r_tables})"
end
o.on('-e', '--exclude_tables=A,B,C', Array, 'Shortcut to exclude a list of tables') { |v| opts[:exclude_tables] = v }
o.on('-d', '--debug', 'Enable Debug Messages') { |_v| opts[:debug] = true }
o.parse!(argv)
opts[:database_url] = argv.shift
opts[:remote_url] = argv.shift
if opts[:database_url].nil?
warn 'Missing Database URL'
puts o
exit 1
end
if opts[:remote_url].nil?
warn 'Missing Remote Taps URL'
puts o
exit 1
end
end
opts
end
|