lib/assimilate/command.rb in assimilate-0.3.5 vs lib/assimilate/command.rb in assimilate-0.4.1

- old
+ new

@@ -18,10 +18,18 @@ opts.on("--commit", "Commit changes to database") do @options[:commit] = true end + opts.on("--subset", "Only consider the fields in the input file") do + @options[:subset] = true + end + + opts.on("--nodeletes", "Do NOT delete existing records that are not present in the input") do + @options[:nodeletes] = true + end + opts.on("--key FIELDNAME", String, "(*extend* only; optional) Hash key to store extended attributes under") do |f| @options[:key] = f end opts.on("--datestamp DATESTRING", String, "(*load* only) Datestamp to record for file batch operation") do |s| @@ -40,23 +48,28 @@ def parse(argv = ARGV) @command = argv.shift filenames = @parser.parse(argv) - raise OptionParser::MissingArgument, "missing config" unless options[:config] - raise OptionParser::MissingArgument, "missing idfield" unless options[:idfield] - raise OptionParser::MissingArgument, "missing domain" unless options[:domain] - raise "missing filename" unless filenames.any? + unless command == 'version' + raise OptionParser::MissingArgument, "missing config" unless options[:config] + raise OptionParser::MissingArgument, "missing idfield" unless options[:idfield] + raise OptionParser::MissingArgument, "missing domain" unless options[:domain] + raise "missing filename" unless filenames.any? + end # argv remnants are filenames [@command, @options, filenames] end def execute(command, options, filenames = nil) filename = filenames.first case command + when 'version' + puts "Assimilate #{Assimilate::VERSION}" + when 'load' raise OptionParser::MissingArgument, "missing datestamp" unless options[:datestamp] results = Assimilate.load(filename, options) logmessage(command, options, results) @@ -90,18 +103,24 @@ Original record count: #{results[:baseline_count]} Final record count: #{results[:final_count]} Unchanged records: #{results[:unchanged_count]} New records: #{results[:adds_count]} #{idsummary(results[:new_ids])} Deletes: #{results[:deletes_count]} #{idsummary(results[:deleted_ids])} +EOT + if options[:nodeletes] + warn "\t\t\tNO DELETIONS" + end + + warn <<-EOT Updates: #{results[:updates_count]} #{idsummary(results[:updated_ids])} EOT if results[:updated_fields].any? $stderr.puts <<-EOT - Counts by field: + Update counts by field: EOT - results[:updated_fields].each do |k,v| + results[:updated_fields].sort.each do |k,v| $stderr.puts <<-EOT - #{k}: #{v} + #{k.ljust(30, '.')}#{"%6d" % v} EOT end end when 'extend' $stderr.puts <<-EOT