<commit_before>module Mutant

  # Comandline parser
  class CLI < CLIParser
    include Adamantium::Flat, Equalizer.new(:matcher, :filter, :strategy, :reporter)

    # Run cli with arguments
    #
    # @param [Array<String>] arguments
    #
    # @return [Fixnum]
    #   returns exit status
    #
    # @api private
    #
    def self.run(*arguments)
      config = new(*arguments).config
      runner = Runner::Config.run(config)
      runner.success? ? EXIT_SUCCESS : EXIT_FAILURE
    rescue Error => exception
      $stderr.puts(exception.message)
      EXIT_FAILURE
    end

    OPTIONS = {
      '--code'       => [:add_filter,   Mutation::Filter::Code ],
      '--debug'      => [:set_debug                            ],
      '-d'           => [:set_debug                            ],
      '--rspec-unit' => [:set_strategy, Strategy::Rspec::Unit  ],
      '--rspec-full' => [:set_strategy, Strategy::Rspec::Full  ],
      '--rspec-dm2'  => [:set_strategy, Strategy::Rspec::DM2   ]
    }.freeze

    # Initialize objecct
    #
    # @param [Array<String>]
    #
    # @return [undefined]
    #
    # @api private
    #
    def initialize(arguments)
      @filters, @matchers = [], []
      super(arguments)
      strategy
      matcher
    end

    # Return config
    #
    # @return [Config]
    #
    # @api private
    #
    def config
      Config.new(
        :debug    => debug?,
        :matcher  => matcher,
        :filter   => filter,
        :strategy => strategy,
        :reporter => reporter
      )
    end
    memoize :config

  private

    # Test for running in debug mode
    #
    # @return [true]
    #   if debug mode is active
    #
    # @return [false]
    #   otherwise
    #
    # @api private
    #
    def debug?
      !!@debug
    end

    # Return mutation filter
    #
    # @return [Mutant::Matcher]
    #
    # @api private
    #
    def filter
      if @filters.empty?
        Mutation::Filter::ALL
      else
        Mutation::Filter::Whitelist.new(@filters)
      end
    end
    memoize :filter

    # Return stratety
    #
    # @return [Strategy]
    #
    # @api private
    #
    def strategy
      @strategy || raise(Error, 'No strategy was set!')
      @strategy.new(self)
    end
    memoize :strategy

    # Return reporter
    #
    # @return [Mutant::Reporter::CLI]
    #
    # @api private
    #
    def reporter
      Mutant::Reporter::CLI.new(self)
    end
    memoize :reporter

    # Return matcher
    #
    # @return [Mutant::Matcher]
    #
    # @raise [CLI::Error]
    #   raises error when matcher is not given
    #
    # @api private
    #
    def matcher
      if @matchers.empty?
        raise Error, 'No matchers given'
      end

      Mutant::Matcher::Chain.build(@matchers)
    end
    memoize :matcher

    # Move processed argument by amount
    #
    # @param [Fixnum] amount
    #   the amount of arguments to be consumed
    #
    # @return [undefined]
    #
    # @api private
    #
    def consume(amount)
      @index += amount
    end

    # Process matcher argument
    #
    # @return [undefined]
    #
    # @api private
    #
    def dispatch_matcher
      argument = current_argument
      consume(1)
      @matchers << Classifier.build(argument)
    end

    # Process option argument
    #
    # @return [Undefined]
    #
    # @api private<commit_msg>Fix cli matchers to only include actual matcher objects<commit_after>module Mutant

  # Comandline parser
  class CLI < CLIParser
    include Adamantium::Flat, Equalizer.new(:matcher, :filter, :strategy, :reporter)

    # Run cli with arguments
    #
    # @param [Array<String>] arguments
    #
    # @return [Fixnum]
    #   returns exit status
    #
    # @api private
    #
    def self.run(*arguments)
      config = new(*arguments).config
      runner = Runner::Config.run(config)
      runner.success? ? EXIT_SUCCESS : EXIT_FAILURE
    rescue Error => exception
      $stderr.puts(exception.message)
      EXIT_FAILURE
    end

    OPTIONS = {
      '--code'       => [:add_filter,   Mutation::Filter::Code ],
      '--debug'      => [:set_debug                            ],
      '-d'           => [:set_debug                            ],
      '--rspec-unit' => [:set_strategy, Strategy::Rspec::Unit  ],
      '--rspec-full' => [:set_strategy, Strategy::Rspec::Full  ],
      '--rspec-dm2'  => [:set_strategy, Strategy::Rspec::DM2   ]
    }.freeze

    # Initialize objecct
    #
    # @param [Array<String>]
    #
    # @return [undefined]
    #
    # @api private
    #
    def initialize(arguments)
      @filters, @matchers = [], []
      super(arguments)
      strategy
      matcher
    end

    # Return config
    #
    # @return [Config]
    #
    # @api private
    #
    def config
      Config.new(
        :debug    => debug?,
        :matcher  => matcher,
        :filter   => filter,
        :strategy => strategy,
        :reporter => reporter
      )
    end
    memoize :config

  private

    # Test for running in debug mode
    #
    # @return [true]
    #   if debug mode is active
    #
    # @return [false]
    #   otherwise
    #
    # @api private
    #
    def debug?
      !!@debug
    end

    # Return mutation filter
    #
    # @return [Mutant::Matcher]
    #
    # @api private
    #
    def filter
      if @filters.empty?
        Mutation::Filter::ALL
      else
        Mutation::Filter::Whitelist.new(@filters)
      end
    end
    memoize :filter

    # Return stratety
    #
    # @return [Strategy]
    #
    # @api private
    #
    def strategy
      @strategy || raise(Error, 'No strategy was set!')
      @strategy.new(self)
    end
    memoize :strategy

    # Return reporter
    #
    # @return [Mutant::Reporter::CLI]
    #
    # @api private
    #
    def reporter
      Mutant::Reporter::CLI.new(self)
    end
    memoize :reporter

    # Return matcher
    #
    # @return [Mutant::Matcher]
    #
    # @raise [CLI::Error]
    #   raises error when matcher is not given
    #
    # @api private
    #
    def matcher
      if @matchers.empty?
        raise Error, 'No matchers given'
      end

      Mutant::Matcher::Chain.build(@matchers)
    end
    memoize :matcher

    # Move processed argument by amount
    #
    # @param [Fixnum] amount
    #   the amount of arguments to be consumed
    #
    # @return [undefined]
    #
    # @api private
    #
    def consume(amount)
      @index += amount
    end

    # Process matcher argument
    #
    # @return [undefined]
    #
    # @api private
    #
    def dispatch_matcher
      argument = current_argument
      consume(1)
      matcher = Classifier.build(argument)
      @matchers << matcher if matcher
    end

    # Process option argument
    #
    # @return [Undefined]
    #
    # @api private
{'fraction_non_alphanumeric': 0.1154130338406975, 'fraction_numerical': 0.0008866558297620806, 'mean_word_length': 1.8153078202995008, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2049186', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2151, 'n_words': 499}