123456789_123456789_123456789_123456789_123456789_

Module: SimpleCov::CLI::Clean

Relationships & Source Files
Defined in: lib/simplecov/cli/clean.rb

Overview

simplecov clean [--dry-run] — remove the coverage report directory (or whatever SimpleCov.coverage_dir resolves to). The --dry-run flag prints what would be deleted without touching disk, for when you're not sure what's in there.

Class Method Summary

Class Method Details

.announce(stdout, opts, message) (mod_func)

[ GitHub ]

  
# File 'lib/simplecov/cli/clean.rb', line 33

def announce(stdout, opts, message)
  stdout.puts("simplecov clean: #{message}") unless opts[:quiet]
end

.parse(args) (mod_func)

[ GitHub ]

  
# File 'lib/simplecov/cli/clean.rb', line 37

def parse(args)
  opts = {dry_run: false, quiet: false}
  OptionParser.new do |o|
    o.on("--dry-run") { opts[:dry_run] = true }
    o.on("-q", "--quiet") { opts[:quiet] = true }
  end.parse(args)
  opts
end

.run(args, stdout:) (mod_func)

[ GitHub ]

  
# File 'lib/simplecov/cli/clean.rb', line 14

def run(args, stdout:, **)
  opts = parse(args)
  dir = SimpleCov::CLI.coverage_dir
  return announce(stdout, opts, "#{dir} doesn't exist; nothing to do") || 0 unless File.directory?(dir)

  sweep(dir, opts, stdout)
  0
end

.sweep(dir, opts, stdout) (mod_func)

[ GitHub ]

  
# File 'lib/simplecov/cli/clean.rb', line 23

def sweep(dir, opts, stdout)
  if opts[:dry_run]
    announce(stdout, opts, "would remove #{dir} (#{Dir["#{dir}/**/*"].size} entries)")
  else
    require "fileutils"
    FileUtils.rm_rf(dir)
    announce(stdout, opts, "removed #{dir}")
  end
end