8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/sql_reporter/parser.rb', line 8
def self.parse
options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: sql_reporter [options] file.json file2.json'
opts.on('-f', '--format FORMAT', String, 'Format of the output file (defaults to pdf, avaliable formats: log , json, png, pdf, xls )') do |f|
options[:format] = f
end
opts.on('--disable-console', 'Disable outputting the report to terminal') do |f|
options[:disable_console] = true
end
opts.on('-o', '--output FILE', String, 'File to write the report to - without extension') do |o|
options[:output] = o
end
opts.on_tail('--version', 'Show version') do
puts SqlReporter::VERSION
exit
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end.parse!
unless ARGV.size == 2
STDERR.puts "[ERROR] Incorrect number of parameters passed (2 files required)"
exit(1)
end
begin
f0 = File.read(ARGV[0])
f1 = File.read(ARGV[1])
rescue StandardError => e
puts e.message
exit(1)
end
begin
master = JSON.load(f0)['data'].values.map do |v|
[v['sql'], SqlReporter::Query.new(v['sql'], v['count'], v['duration'] || 0, v['cached_count'] || 0)]
end.to_h
feature = JSON.load(f1)['data'].values.map do |v|
[v['sql'], SqlReporter::Query.new(v['sql'], v['count'], v['duration'] || 0, v['cached_count'] || 0)]
end.to_h
rescue JSON::ParserError
STDERR.puts 'One of the files provided is not a correctly formatted JSON file'
exit(1)
end
master_key = ARGV[0]
feature_key = ARGV[0] == ARGV[1] ? ARGV[0] + '_copy' : ARGV[1]
{ master_key => master, feature_key => feature, format: options[:format] }.merge(options)
end
|