Sha256: 387802126bf42edea6023077f03e75532890a678ee54b8b6f0be0817b6ad87ba

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

require 'forwardable'
require_relative 'input'
require_relative 'report/report'
require_relative 'report/formatter'
require_relative 'report/heading_formatter'

module Reek
  module CLI
    #
    # Interprets the options set from the command line
    #
    class OptionInterpreter
      include CLI::Input

      extend Forwardable

      def_delegators :@options, :smells_to_detect

      def initialize(options)
        @options = options
        @argv = @options.argv
      end

      def reporter
        @reporter ||=
          report_class.new(
            warning_formatter: warning_formatter,
            report_formatter: Report::Formatter,
            sort_by_issue_count: sort_by_issue_count,
            heading_formatter: heading_formatter)
      end

      def report_class
        case @options.report_format
        when :yaml
          Report::YAMLReport
        when :json
          Report::JSONReport
        when :html
          Report::HTMLReport
        else # :text
          Report::TextReport
        end
      end

      def warning_formatter
        klass = if @options.show_links
                  Report::WikiLinkWarningFormatter
                else
                  Report::SimpleWarningFormatter
                end
        klass.new(location_formatter)
      end

      def location_formatter
        case @options.location_format
        when :single_line
          Report::SingleLineLocationFormatter
        when :plain
          Report::BlankLocationFormatter
        else # :numbers
          Report::DefaultLocationFormatter
        end
      end

      def heading_formatter
        if @options.show_empty
          Report::HeadingFormatter::Verbose
        else
          Report::HeadingFormatter::Quiet
        end
      end

      def sort_by_issue_count
        @options.sorting == :smelliness
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reek-2.1.0 lib/reek/cli/option_interpreter.rb