Sha256: c2769502178b3e2b9484c7bd3a945bc2cd19fca9b1b9443be4cc2ff759fe00f9

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require "rubycritic/cli/options"
require "rubycritic/cli/application"

require "skunk"
require "skunk/rubycritic/analysed_module"
require "skunk/cli/options"
require "skunk/cli/command_factory"
require "skunk/cli/commands/status_sharer"

module Skunk
  module Cli
    # Knows how to execute command line commands
    # :reek:InstanceVariableAssumption
    class Application < RubyCritic::Cli::Application
      COVERAGE_FILE = "coverage/.resultset.json"

      def initialize(argv)
        @options = Skunk::Cli::Options.new(argv)
      end

      # :reek:UncommunicativeVariableName
      def execute
        warn_coverage_info unless File.exist?(COVERAGE_FILE)

        # :reek:NilCheck
        @parsed_options = @options.parse.to_h
        command = Skunk::Cli::CommandFactory.create(@parsed_options)
        reporter = command.execute

        print(reporter.status_message)
        if command.sharing?
          share_status_message = command.share(reporter)
          print(share_status_message)
        end

        reporter.status
      rescue OptionParser::InvalidOption => e
        warn "Error: #{e}"
        STATUS_ERROR
      end

      private

      def warn_coverage_info
        warn "warning: Couldn't find coverage info at #{COVERAGE_FILE}."
        warn "warning: Having no coverage metrics will make your SkunkScore worse."
      end

      # :reek:NilCheck
      def print(message)
        filename = @parsed_options[:output_filename]
        if filename.nil?
          $stdout.puts(message)
        else
          File.open(filename, "a") { |file| file << message }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
skunk-0.5.2 lib/skunk/cli/application.rb