Sha256: 7ab0f6e5eaa0f1a7e4b54d607c3ae1c9dbc25233b7594dc36dd573b70ba10599

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'undercover'
require 'rainbow'

module Undercover
  module CLI
    # TODO: Report calls >parser< for each file instead of
    # traversing the whole project at first!

    WARNINGS_TO_S = {
      stale_coverage: Rainbow('♻️  Coverage data is older than your ' \
        'latest changes. Re-run tests to update').yellow,
      no_changes: Rainbow('✅ No reportable changes').green
    }.freeze

    WARNINGS_TO_EXITCODE = {stale_coverage: 1, no_changes: 0}.freeze

    # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
    def self.run(args)
      opts = Undercover::Options.new.parse(args)
      syntax_version(opts.syntax_version)
      report = Undercover::Report.new(changeset(opts), opts).build

      error = report.validate(opts.lcov)
      if error
        puts(WARNINGS_TO_S[error])
        return WARNINGS_TO_EXITCODE[error]
      end

      warnings = report.build_warnings
      puts Undercover::Formatter.new(warnings)
      warnings.any? ? 1 : 0
    end
    # rubocop:enable Metrics/MethodLength, Metrics/AbcSize

    def self.syntax_version(version)
      return unless version

      Imagen.parser_version = version
    end

    def self.changeset(opts)
      git_dir = File.join(opts.path, opts.git_dir)
      Undercover::Changeset.new(git_dir, opts.compare)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
undercover-0.2.1 lib/undercover/cli.rb