Sha256: 055b41f8cabbf2bb7b7650420fec4853423374a056c5410850ef09cd5dd26776

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

require_relative 'options'
require_relative 'reek_command'
require_relative 'option_interpreter'
require_relative '../configuration/app_configuration'

module Reek
  module CLI
    #
    # Represents an instance of a Reek application.
    # This is the entry point for all invocations of Reek from the
    # command line.
    #
    class Application
      attr_reader :configuration

      private_attr_accessor :status
      private_attr_reader :command, :options

      def initialize(argv)
        @options = configure_options(argv)
        @status = options.success_exit_code
        @configuration = configure_app_configuration(options.config_file)
        @command = ReekCommand.new(OptionInterpreter.new(options))
      end

      def execute
        command.execute self
        status
      end

      def report_success
        self.status = options.success_exit_code
      end

      def report_smells
        self.status = options.failure_exit_code
      end

      private

      def configure_options(argv)
        Options.new(argv).parse
      rescue OptionParser::InvalidOption => error
        $stderr.puts "Error: #{error}"
        exit Options::DEFAULT_ERROR_EXIT_CODE
      end

      def configure_app_configuration(config_file)
        Configuration::AppConfiguration.from_path(config_file)
      rescue Reek::Configuration::ConfigFileException => error
        $stderr.puts "Error: #{error}"
        exit Options::DEFAULT_ERROR_EXIT_CODE
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
reek-3.10.1 lib/reek/cli/application.rb
reek-3.10.0 lib/reek/cli/application.rb
reek-3.9.1 lib/reek/cli/application.rb
reek-3.9.0 lib/reek/cli/application.rb
reek-3.8.3 lib/reek/cli/application.rb
reek-3.8.2 lib/reek/cli/application.rb