Sha256: 2f2eec92c431cd4564e08544c68ceeb7cced2b2c77fcf42314593969ff8250d9

Contents?: true

Size: 1020 Bytes

Versions: 3

Compression:

Stored size: 1020 Bytes

Contents

#!/usr/bin/env ruby
require 'sql_tracker/report'
require 'json'
require 'optparse'

options = {}

parser = OptionParser.new(ARGV) do |o|
  o.banner = 'Usage: sql_tracker [file.json]+ [--sort-by=COLUMN]'

  o.on('-s', '--sort-by COLUMN', 'The name of column that is used for sorting the table. Options: count, duration') do |arg|
    options[:sort_by] = arg if %(count duration).include?(arg)
  end
end

parser.parse!
parser.abort(parser.help) if ARGV.empty?

default_options = { sort_by: 'count' }

options = default_options.merge(options)

reports = []
until ARGV.empty?
  begin
    file = ARGV.pop
    report = SqlTracker::Report.new(JSON.load(IO.binread(file)))
    if report.valid?
      reports << report
    else
      STDOUT.puts "Skip incompatible file: #{file}"
    end
  rescue => e
    STDERR.puts "Error when parsing #{file}: #{e.inspect}"
  end
end

if reports.empty?
  STDERR.puts 'Unable to find sql_tracker json dump to generate report'
  exit
end

report = reports.inject(:+)
report.print_text(options)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sql_tracker-1.3.0 bin/sql_tracker
sql_tracker-1.2.1 bin/sql_tracker
sql_tracker-1.2.0 bin/sql_tracker