exe/deprecations in ten_years_rails-0.2.0 vs exe/deprecations in ten_years_rails-1.0.1
- old
+ new
@@ -1,12 +1,14 @@
#!/usr/bin/env ruby
require "json"
-require "colorize"
+require "rainbow"
require "optparse"
require "set"
-def run_tests(deprecation_warnings, tracker_mode:, next_mode:)
+def run_tests(deprecation_warnings, opts = {})
+ tracker_mode = opts[:tracker_mode]
+ next_mode = opts[:next_mode]
rspec_command = if next_mode
"bin/next rspec"
else
"bundle exec rspec"
end
@@ -14,31 +16,32 @@
command = "DEPRECATION_TRACKER=#{tracker_mode} #{rspec_command} #{deprecation_warnings.keys.join(" ")}"
puts command
exec command
end
-def print_info(deprecation_warnings, verbose: false)
+def print_info(deprecation_warnings, opts = {})
+ verbose = !!opts[:verbose]
frequency_by_message = deprecation_warnings.each_with_object({}) do |(test_file, messages), hash|
messages.each do |message|
hash[message] ||= { test_files: Set.new, occurrences: 0 }
hash[message][:test_files] << test_file
hash[message][:occurrences] += 1
end
end.sort_by {|message, data| data[:occurrences] }.reverse.to_h
puts "Ten most common deprecation warnings:".underline
frequency_by_message.take(10).each do |message, data|
- puts "Occurrences: #{data.fetch(:occurrences)}".bold
+ puts Rainbow("Occurrences: #{data.fetch(:occurrences)}").bold
puts "Test files: #{data.fetch(:test_files).to_a.join(" ")}" if verbose
- puts message.red
+ puts Rainbow(message).red
puts "----------"
end
end
options = {}
option_parser = OptionParser.new do |opts|
- opts.banner = <<~MESSAGE
+ opts.banner = <<-MESSAGE
Usage: #{__FILE__.to_s} [options] [mode]
Parses the deprecation warning shitlist and show info or run tests.
Examples:
@@ -99,12 +102,12 @@
case options.fetch(:mode, "info")
when "run" then run_tests(deprecation_warnings, next_mode: options[:next], tracker_mode: options[:tracker_mode])
when "info" then print_info(deprecation_warnings, verbose: options[:verbose])
when nil
- STDERR.puts "Must pass a mode: run or info".red
+ STDERR.puts Rainbow("Must pass a mode: run or info").red
puts option_parser
exit 1
else
- STDERR.puts "Unknown mode: #{options[:mode]}".red
+ STDERR.puts Rainbow("Unknown mode: #{options[:mode]}").red
exit 1
end