lib/spoom/cli/coverage.rb in spoom-1.0.8 vs lib/spoom/cli/coverage.rb in spoom-1.0.9

- old
+ new

@@ -28,11 +28,11 @@ save_dir = options[:save] return unless save_dir FileUtils.mkdir_p(save_dir) file = "#{save_dir}/#{snapshot.commit_sha || snapshot.timestamp}.json" File.write(file, snapshot.to_json) - puts "\nSnapshot data saved under #{file}" + say("\nSnapshot data saved under `#{file}`") end desc "timeline", "Replay a project and collect metrics" option :from, type: :string, desc: "From commit date" option :to, type: :string, default: Time.now.strftime("%F"), desc: "To commit date" @@ -45,18 +45,22 @@ sorbet = options[:sorbet] sha_before = Spoom::Git.last_commit(path: path) unless sha_before say_error("Not in a git repository") - $stderr.puts "\nSpoom needs to checkout into your previous commits to build the timeline." + say_error("\nSpoom needs to checkout into your previous commits to build the timeline.", status: nil) exit(1) end unless Spoom::Git.workdir_clean?(path: path) say_error("Uncommited changes") - $stderr.puts "\nSpoom needs to checkout into your previous commits to build the timeline." - $stderr.puts "\nPlease git commit or git stash your changes then try again." + say_error(<<~ERR, status: nil) + + Spoom needs to checkout into your previous commits to build the timeline." + + Please `git commit` or `git stash` your changes then try again + ERR exit(1) end save_dir = options[:save] FileUtils.mkdir_p(save_dir) if save_dir @@ -72,17 +76,17 @@ timeline = Spoom::Timeline.new(from, to, path: path) ticks = timeline.ticks if ticks.empty? - say_error("No commits to replay, try different --from and --to options") + say_error("No commits to replay, try different `--from` and `--to` options") exit(1) end ticks.each_with_index do |sha, i| date = Spoom::Git.commit_time(sha, path: path) - puts "Analyzing commit #{sha} - #{date&.strftime('%F')} (#{i + 1} / #{ticks.size})" + say("Analyzing commit `#{sha}` - #{date&.strftime('%F')} (#{i + 1} / #{ticks.size})") Spoom::Git.checkout(sha, path: path) snapshot = T.let(nil, T.nilable(Spoom::Coverage::Snapshot)) if options[:bundle_install] @@ -94,16 +98,16 @@ snapshot = Spoom::Coverage.snapshot(path: path, sorbet_bin: sorbet) end next unless snapshot snapshot.print(indent_level: 2) - puts "\n" + say("\n") next unless save_dir file = "#{save_dir}/#{sha}.json" File.write(file, snapshot.to_json) - puts " Snapshot data saved under #{file}\n\n" + say(" Snapshot data saved under `#{file}`\n\n") end Spoom::Git.checkout(sha_before, path: path) end desc "report", "Produce a typing coverage report" @@ -144,24 +148,24 @@ ) report = Spoom::Coverage.report(snapshots, palette: palette, path: exec_path) file = options[:file] File.write(file, report.html) - puts "Report generated under #{file}" - puts "\nUse #{colorize('spoom coverage open', :blue)} to open it." + say("Report generated under `#{file}`") + say("\nUse `spoom coverage open` to open it.") end desc "open", "Open the typing coverage report" def open(file = "spoom_report.html") unless File.exist?(file) - say_error("No report file to open #{colorize(file, :blue)}") - $stderr.puts <<~OUT + say_error("No report file to open `#{file}`") + say_error(<<~ERR, status: nil) - If you already generated a report under another name use #{colorize('spoom coverage open PATH', :blue)}. + If you already generated a report under another name use #{blue('spoom coverage open PATH')}. - To generate a report run #{colorize('spoom coverage report', :blue)}. - OUT + To generate a report run #{blue('spoom coverage report')}. + ERR exit(1) end exec("open #{file}") end @@ -169,33 +173,33 @@ no_commands do def parse_time(string, option) return nil unless string Time.parse(string) rescue ArgumentError - say_error("Invalid date `#{string}` for option #{option} (expected format YYYY-MM-DD)") + say_error("Invalid date `#{string}` for option `#{option}` (expected format `YYYY-MM-DD`)") exit(1) end def bundle_install(path, sha) opts = {} opts[:chdir] = path out, status = Open3.capture2e("bundle install", opts) unless status.success? - say_error("Can't run `bundle install` for commit #{sha}. Skipping snapshot") - $stderr.puts(out) + say_error("Can't run `bundle install` for commit `#{sha}`. Skipping snapshot") + say_error(out, status: nil) return false end true end def message_no_data(file) - say_error("No snapshot files found in #{colorize(file, :blue)}") - $stderr.puts <<~OUT + say_error("No snapshot files found in `#{file}`") + say_error(<<~ERR, status: nil) - If you already generated snapshot files under another directory use #{colorize('spoom coverage report PATH', :blue)}. + If you already generated snapshot files under another directory use #{blue('spoom coverage report PATH')}. - To generate snapshot files run #{colorize('spoom coverage timeline --save-dir spoom_data', :blue)}. - OUT + To generate snapshot files run #{blue('spoom coverage timeline --save-dir spoom_data')}. + ERR end end end end end