<commit_before>require 'optparse'

module Spinach
  # The cli is a class responsible of handling all the command line interface
  # logic.
  #
  class Cli
    # @param [Array<String>] arguments
    #   The command line arguments
    #
    # @api public
    def initialize(args = ARGV)
      @args = args
    end

    # Runs all the features.
    #
    # @return [true, false]
    #   The exit status - true for success, false for failure.
    #
    # @api public
    def run
      options

      return true if Spinach.config.generate

      Spinach::Runner.new(feature_files).run
    end

    # @return [Hash]
    #   A hash of options separated by its type.
    #
    # @example
    #   Cli.new.options
    #   # => { reporter: { backtrace: true } }
    #
    # @api public
    def options
      @options ||= parse_options
    end

    # Uses given args to list the feature files to run. It will find a single
    # feature, features in a folder and subfolders or every feature file in the
    # feature path.
    #
    # @return [Array]
    #   An array with the feature file names.
    #
    # @api public
    def feature_files
      files_to_run = []

      @args.each do |arg|
        if arg.match(/\.feature/)
          if File.exists? arg.gsub(/:\d*/, '')
            files_to_run << arg
          else
            fail! "#{arg} could not be found"
          end
        elsif File.directory?(arg)
          files_to_run << Dir.glob(File.join(arg, '**', '*.feature'))
        else
          fail! "invalid argument - #{arg}"
        end
      end

      if !files_to_run.empty?
        files_to_run.flatten
      else
        Dir.glob(File.join(Spinach.config[:features_path], '**', '*.feature'))
      end
    end

    private

    # Parses the arguments into options.<commit_msg>Ignore weird arguments being passed by JRuby<commit_after>require 'optparse'

module Spinach
  # The cli is a class responsible of handling all the command line interface
  # logic.
  #
  class Cli
    # @param [Array<String>] arguments
    #   The command line arguments
    #
    # @api public
    def initialize(args = ARGV)
      @args = args
    end

    # Runs all the features.
    #
    # @return [true, false]
    #   The exit status - true for success, false for failure.
    #
    # @api public
    def run
      options

      return true if Spinach.config.generate

      Spinach::Runner.new(feature_files).run
    end

    # @return [Hash]
    #   A hash of options separated by its type.
    #
    # @example
    #   Cli.new.options
    #   # => { reporter: { backtrace: true } }
    #
    # @api public
    def options
      @options ||= parse_options
    end

    # Uses given args to list the feature files to run. It will find a single
    # feature, features in a folder and subfolders or every feature file in the
    # feature path.
    #
    # @return [Array]
    #   An array with the feature file names.
    #
    # @api public
    def feature_files
      files_to_run = []

      @args.each do |arg|
        if arg.match(/\.feature/)
          if File.exists? arg.gsub(/:\d*/, '')
            files_to_run << arg
          else
            fail! "#{arg} could not be found"
          end
        elsif File.directory?(arg)
          files_to_run << Dir.glob(File.join(arg, '**', '*.feature'))
        elsif arg != "{}"
          fail! "invalid argument - #{arg}"
        end
      end

      if !files_to_run.empty?
        files_to_run.flatten
      else
        Dir.glob(File.join(Spinach.config[:features_path], '**', '*.feature'))
      end
    end

    private

    # Parses the arguments into options.
{'fraction_non_alphanumeric': 0.10215350635008283, 'fraction_numerical': 0.0, 'mean_word_length': 1.9077046548956662, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, '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': '1024421', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1089, 'n_words': 350}