lib/taps/cli.rb in taps2-0.5.5 vs lib/taps/cli.rb in taps2-0.6.0

- old
+ new

@@ -7,11 +7,11 @@ Taps::Config.taps_database_url = ENV['TAPS_DATABASE_URL'] || ENV['DATABASE_URL'] || begin # this is dirty but it solves a weird problem where the tempfile disappears mid-process require 'sqlite3' $__taps_database = Tempfile.new('taps.db') - $__taps_database.open() + $__taps_database.open "sqlite://#{$__taps_database.path}" end module Taps class Cli @@ -21,11 +21,11 @@ @argv = argv end def run method = (argv.shift || 'help').to_sym - if [:pull, :push, :server, :version].include? method + if %i[pull push server version].include? method send(method) else help end end @@ -57,16 +57,14 @@ Taps::Config.login = opts[:login] Taps::Config.password = opts[:password] Taps::Config.verify_database_url require 'taps/server' - Taps::Server.run!({ - :port => opts[:port], - :environment => :production, - :logging => true, - :dump_errors => true, - }) + Taps::Server.run!(port: opts[:port], + environment: :production, + logging: true, + dump_errors: true) end def version puts Taps.version end @@ -83,78 +81,78 @@ Add '-h' to any command to see their usage EOHELP end def serveroptparse - opts={:port => 5000, :database_url => nil, :login => nil, :password => nil, :debug => false} + opts = { port: 5000, database_url: nil, login: nil, password: nil, debug: false } OptionParser.new do |o| - o.banner = "Usage: #{File.basename($0)} server [OPTIONS] <local_database_url> <login> <password>" - o.define_head "Start a taps database import/export server" + o.banner = "Usage: #{File.basename($PROGRAM_NAME)} server [OPTIONS] <local_database_url> <login> <password>" + o.define_head 'Start a taps database import/export server' - o.on("-p", "--port=N", "Server Port") { |v| opts[:port] = v.to_i if v.to_i > 0 } - o.on("-d", "--debug", "Enable Debug Messages") { |v| opts[:debug] = true } + o.on('-p', '--port=N', 'Server Port') { |v| opts[:port] = v.to_i if v.to_i > 0 } + o.on('-d', '--debug', 'Enable Debug Messages') { |_v| opts[:debug] = true } o.parse!(argv) opts[:database_url] = argv.shift opts[:login] = argv.shift || ENV['TAPS_LOGIN'] opts[:password] = argv.shift || ENV['TAPS_PASSWORD'] if opts[:database_url].nil? - $stderr.puts "Missing Database URL" + warn 'Missing Database URL' puts o exit 1 end if opts[:login].nil? - $stderr.puts "Missing Login" + warn 'Missing Login' puts o exit 1 end if opts[:password].nil? - $stderr.puts "Missing Password" + warn 'Missing Password' puts o exit 1 end end opts end def clientoptparse(cmd) - opts={:default_chunksize => 1000, :database_url => nil, :remote_url => nil, :debug => false, :resume_filename => nil, :disable_compresion => false, :indexes_first => false} + 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($0)} #{cmd} [OPTIONS] <local_database_url> <remote_url>" + 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" + o.define_head 'Pull a database from a taps server' when :push - o.define_head "Push a database to a taps server" + 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("|") + 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.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? - $stderr.puts "Missing Database URL" + warn 'Missing Database URL' puts o exit 1 end if opts[:remote_url].nil? - $stderr.puts "Missing Remote Taps URL" + warn 'Missing Remote Taps URL' puts o exit 1 end end @@ -181,16 +179,13 @@ Taps::Config.verify_database_url(database_url) require 'taps/operation' - newsession = session.merge({ - :default_chunksize => opts[:default_chunksize], - :disable_compression => opts[:disable_compression], - :resume => true, - }) + newsession = session.merge(default_chunksize: opts[:default_chunksize], + disable_compression: opts[:disable_compression], + resume: true) Taps::Operation.factory(method, database_url, remote_url, newsession).run end - end end