Sha256: 3fbed5a0de490978c348b5654e05f3b9e9119fb69a0bf42ae3ca11c1f9e4cf75

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'reek/cli/options'
require 'reek/cli/reek_command'
require 'reek/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
      STATUS_SUCCESS = 0
      STATUS_ERROR   = 1
      STATUS_SMELLS  = 2

      def initialize(argv)
        @status = STATUS_SUCCESS
        options_parser = Options.new(argv)
        begin
          @options = options_parser.parse
          @command = ReekCommand.new(OptionInterpreter.new(@options))
          initialize_configuration
        rescue OptionParser::InvalidOption, Reek::Configuration::ConfigFileException => error
          $stderr.puts "Error: #{error}"
          @status = STATUS_ERROR
        end
      end

      def execute
        return @status if error_occured?
        @command.execute self
        @status
      end

      def initialize_configuration
        Configuration::AppConfiguration.initialize_with @options
      end

      def output(text)
        print text
      end

      def report_success
        @status = STATUS_SUCCESS
      end

      def report_smells
        @status = STATUS_SMELLS
      end

      private

      def error_occured?
        @status == STATUS_ERROR
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reek-2.0.4 lib/reek/cli/application.rb
reek-2.0.3 lib/reek/cli/application.rb