<commit_before>require 'thor/core_ext/hash_with_indifferent_access'
require 'thor/core_ext/ordered_hash'
require 'thor/error'
require 'thor/shell'
require 'thor/invocation'
require 'thor/parser'
require 'thor/task'
require 'thor/util'

class Thor
  HELP_MAPPINGS       = %w(-h -? --help -D)
  THOR_RESERVED_WORDS = %w(invoke shell options behavior root destination_root relative_root)

  module Base
    attr_accessor :options

    # It receives arguments in an Array and two hashes, one for options and
    # other for configuration.
    #
    # Notice that it does not check if all required arguments were supplied.
    # It should be done by the parser.
    #
    # ==== Parameters
    # args<Array[Object]>:: An array of objects. The objects are applied to their
    #                       respective accessors declared with <tt>argument</tt>.
    #
    # options<Hash>:: An options hash that will be available as self.options.
    #                 The hash given is converted to a hash with indifferent
    #                 access, magic predicates (options.skip?) and then frozen.
    #
    # config<Hash>:: Configuration for this Thor class.
    #
    def initialize(args=[], options={}, config={})
      Thor::Arguments.parse(self.class.arguments, args).each do |key, value|
        send("#{key}=", value)
      end

      parse_options = self.class.class_options

      options = if options.is_a?(Array)
        task_options  = config.delete(:task_options) # hook for start
        parse_options = parse_options.merge(task_options) if task_options
        Thor::Options.parse(parse_options, options)
      else
        Thor::Options.parse(parse_options, []).merge(options)
      end

      self.options = Thor::CoreExt::HashWithIndifferentAccess.new(options).freeze
    end

    class << self
      def included(base) #:nodoc:
        base.send :extend,  ClassMethods
        base.send :include, Invocation
        base.send :include, Shell
      end

      # Returns the classes that inherits from Thor or Thor::Group.
      #
      # ==== Returns
      # Array[Class]
      #
      def subclasses
        @subclasses ||= []
      end

      # Returns the files where the subclasses are kept.
      #
      # ==== Returns
      # Hash[path<String> => Class]
      #
      def subclass_files
        @subclass_files ||= Hash.new{ |h,k| h[k] = [] }
      end

      # Whenever a class inherits from Thor or Thor::Group, we should track the
      # class and the file on Thor::Base. This is the method responsable for it.
      # Also adds the source root to the source paths if the klass respond to it.
      #
      def register_klass_file(klass) #:nodoc:
        file = caller[1].match(/(.*):\d+/)[1]
        Thor::Base.subclasses << klass unless Thor::Base.subclasses.include?(klass)

        if klass.respond_to?(:source_root) && !klass.source_paths.include?(klass.source_root)
          klass.source_paths << klass.source_root
        end

        file_subclasses = Thor::Base.subclass_files[File.expand_path(file)]
        file_subclasses << klass unless file_subclasses.include?(klass)
      end
    end

    module ClassMethods
      # Adds an argument to the class and creates an attr_accessor for it.
      #
      # Arguments are different from options in several aspects. The first one
      # is how they are parsed from the command line, arguments are retrieved
      # from position:
      #
      #   thor task NAME
      #
      # Instead of:
      #
      #   thor task --name=NAME<commit_msg>Ensure that source root is always added to the beginning of source paths.<commit_after>require 'thor/core_ext/hash_with_indifferent_access'
require 'thor/core_ext/ordered_hash'
require 'thor/error'
require 'thor/shell'
require 'thor/invocation'
require 'thor/parser'
require 'thor/task'
require 'thor/util'

class Thor
  HELP_MAPPINGS       = %w(-h -? --help -D)
  THOR_RESERVED_WORDS = %w(invoke shell options behavior root destination_root relative_root)

  module Base
    attr_accessor :options

    # It receives arguments in an Array and two hashes, one for options and
    # other for configuration.
    #
    # Notice that it does not check if all required arguments were supplied.
    # It should be done by the parser.
    #
    # ==== Parameters
    # args<Array[Object]>:: An array of objects. The objects are applied to their
    #                       respective accessors declared with <tt>argument</tt>.
    #
    # options<Hash>:: An options hash that will be available as self.options.
    #                 The hash given is converted to a hash with indifferent
    #                 access, magic predicates (options.skip?) and then frozen.
    #
    # config<Hash>:: Configuration for this Thor class.
    #
    def initialize(args=[], options={}, config={})
      Thor::Arguments.parse(self.class.arguments, args).each do |key, value|
        send("#{key}=", value)
      end

      parse_options = self.class.class_options

      options = if options.is_a?(Array)
        task_options  = config.delete(:task_options) # hook for start
        parse_options = parse_options.merge(task_options) if task_options
        Thor::Options.parse(parse_options, options)
      else
        Thor::Options.parse(parse_options, []).merge(options)
      end

      self.options = Thor::CoreExt::HashWithIndifferentAccess.new(options).freeze
    end

    class << self
      def included(base) #:nodoc:
        base.send :extend,  ClassMethods
        base.send :include, Invocation
        base.send :include, Shell
      end

      # Returns the classes that inherits from Thor or Thor::Group.
      #
      # ==== Returns
      # Array[Class]
      #
      def subclasses
        @subclasses ||= []
      end

      # Returns the files where the subclasses are kept.
      #
      # ==== Returns
      # Hash[path<String> => Class]
      #
      def subclass_files
        @subclass_files ||= Hash.new{ |h,k| h[k] = [] }
      end

      # Whenever a class inherits from Thor or Thor::Group, we should track the
      # class and the file on Thor::Base. This is the method responsable for it.
      # Also adds the source root to the source paths if the klass respond to it.
      #
      def register_klass_file(klass) #:nodoc:
        file = caller[1].match(/(.*):\d+/)[1]
        Thor::Base.subclasses << klass unless Thor::Base.subclasses.include?(klass)

        if klass.respond_to?(:source_root) && !klass.source_paths.include?(klass.source_root)
          klass.source_paths.unshift(klass.source_root)
        end

        file_subclasses = Thor::Base.subclass_files[File.expand_path(file)]
        file_subclasses << klass unless file_subclasses.include?(klass)
      end
    end

    module ClassMethods
      # Adds an argument to the class and creates an attr_accessor for it.
      #
      # Arguments are different from options in several aspects. The first one
      # is how they are parsed from the command line, arguments are retrieved
      # from position:
      #
      #   thor task NAME
      #
      # Instead of:
      #
      #   thor task --name=NAME
{'fraction_non_alphanumeric': 0.09648382559774965, 'fraction_numerical': 0.0005625879043600563, 'mean_word_length': 2.5325384997516145, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 17, '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': '3660589', 'n_tokens_mistral': 2038, 'n_tokens_neox': 2024, 'n_words': 634}