Sha256: 937d90fc6a37b981349c9330de72de505862bf14812894ed4fdce6f1f8e6d8a7
Contents?: true
Size: 1.36 KB
Versions: 2
Compression:
Stored size: 1.36 KB
Contents
#!/usr/bin/env ruby require 'sql_tracker/terminal' require 'sql_tracker/report' require 'json' require 'optparse' options = {} default_options = { sort_by: 'count', terminal_width: SqlTracker::Terminal.width } 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 o.on('-w', '--terminal-width WIDTH', Integer, "The width of the printed report. " \ "Default: #{default_options[:terminal_width]}. " \ "Minimum #{SqlTracker::Terminal::MIN_WIDTH}") do |arg| options[:terminal_width] = arg if arg >= SqlTracker::Terminal::MIN_WIDTH end end parser.parse! parser.abort(parser.help) if ARGV.empty? 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sql_tracker-1.3.2 | bin/sql_tracker |
sql_tracker-1.3.1 | bin/sql_tracker |