# encoding: utf-8 require 'thor' class Strike < Thor require 'strike/interpreter' require 'strike/agent' include Thor::Actions desc 'version', 'Show version' def version $stdout.puts "v#{IO.read(File.expand_path('../../VERSION', __FILE__))}" end desc 'dump ', 'Dump the to STDOUT.' long_desc <<-DESC Dump the following the table definitions defined in the (defaults to `Strikefile`). The default dump output is STDOUT. The must have one of the following formats: \x5\tmysql://user:password@host/database \x5\tmysql://user@host/database Usage example: $ strike dump mysql://root@localhost/db_production > dump.sql $ strike dump mysql://root:secret@localhost/db_production --profile=tables.rb > dump.sql The tables are defined with a DSL, which is a wrapper arround the obfuscation types defined in the MyObfuscate gem. Example: \x5\t# tables.rb \x5\ttable :users do |t| \x5\t # t.column_name :obfuscation_type \x5\t t.name :first_name \x5\t t.email :email \x5\tend DESC method_option :profile, aliases: '-p', type: :string, default: 'Strikefile', required: true, desc: 'Profile with the table definitions.' method_option :output, aliases: '-o', type: :string, required: false, desc: 'Output file. If none is given, outputs to STDOUT.' def dump(database_url) file = options[:profile] if options[:output] modes = File::CREAT|File::TRUNC|File::RDWR output = File.new(options[:output], modes, 0644) end if file && File.exist?(file) File.open(file) do |profile| tables = Interpreter.new.parse(profile.read) Agent.new.call(self, database_url, tables, output || $stdout) end else $stdout.puts "Profile Error: No such file #{file}" end ensure output.close if output end end