<commit_before>require 'slop/option'
require 'slop/version'

class Slop
  include Enumerable

  class MissingArgumentError < RuntimeError; end
  class InvalidArgumentError < RuntimeError; end
  class InvalidOptionError < RuntimeError; end

  # Parses the items from a CLI format into a friendly object.
  #
  # @param [Array] items Items to parse into options.
  # @yield Specify available CLI arguments using Slop# methods such as Slop#banner and Slop#option
  # @return [Slop] Returns an instance of Slop.
  # @example Specifying three options to parse:
  #  opts = Slops.parse do
  #    on :v, :verbose, 'Enable verbose mode'
  #    on :n, :name,    'Your name'
  #    on :a, :age,     'Your age'
  #  end
  #  -------
  #  program.rb --verbose -n 'Emily' -a 25
  # @see Slop#banner
  # @see Slop#option
  def self.parse(items=ARGV, options={}, &block)
    initialize_and_parse(items, false, options, &block)
  end

  # Identical to {Slop.parse}, but removes parsed options from the original Array.
  #
  # @yield Specify available CLI arguments using Slop# methods such as Slop#banner and Slop#option
  # @return [Slop] Returns an instance of Slop.
  def self.parse!(items=ARGV, options={}, &block)
    initialize_and_parse(items, true, options, &block)
  end

  # @return [Options]
  attr_reader :options

  attr_writer :banner
  attr_accessor :longest_flag

  # @param [Hash] options
  # @option options [Boolean] :help Automatically add the `help` option
  # @option options [Boolean] :strict Strict mode raises when a non listed
  #   option is found, false by default
  def initialize(options={}, &block)
    @options = Options.new
    @banner = nil
    @longest_flag = 0
    @strict = options[:strict]
    @invalid_options = []

    if block_given?
      block.arity == 1 ? yield(self) : instance_eval(&block)
    end

    if options[:help]
      on :h, :help, 'Print this help message', :tail => true do
        puts help
        exit
      end
    end
  end

  # Set or return banner text.
  #
  # @param [String] text Displayed banner text.
  # @return [String] Returns current banner.
  # @example
  #   opts = Slop.parse do
  #     banner "Usage - ruby foo.rb [arguments]"
  #   end
  # @see Slop#to_s
  def banner(text=nil)
    @banner = text if text
    @banner
  end

  # Parse a list of options, leaving the original Array unchanged.
  #
  # @param items
  def parse(items=ARGV, &block)
    parse_items items, &block
  end

  # Parse a list of options, removing parsed options from the original Array.
  #
  # @param items
  def parse!(items=ARGV, &block)
    parse_items items, true, &block
  end

  # Enumerable interface
  def each
    return enum_for(:each) unless block_given?
    @options.each { |option| yield option }
  end

  # Return the value of an option via the subscript operator.
  #
  # @param [Symbol] key Option symbol.
  # @return [Object] Returns the object associated with that option.
  # @example
  #   opts[:name]
  #   #=> "Emily"
  # @see Slop#method_missing
  def [](key)
    option = @options[key]
    option ? option.argument_value : nil
  end

  # Specify an option with a short or long version, description and type.
  #
  # @param [*] args Option configuration.
  # @option args [Symbol, String] :short_flag Short option name.<commit_msg>no need for ternary here<commit_after>require 'slop/option'
require 'slop/version'

class Slop
  include Enumerable

  class MissingArgumentError < RuntimeError; end
  class InvalidArgumentError < RuntimeError; end
  class InvalidOptionError < RuntimeError; end

  # Parses the items from a CLI format into a friendly object.
  #
  # @param [Array] items Items to parse into options.
  # @yield Specify available CLI arguments using Slop# methods such as Slop#banner and Slop#option
  # @return [Slop] Returns an instance of Slop.
  # @example Specifying three options to parse:
  #  opts = Slops.parse do
  #    on :v, :verbose, 'Enable verbose mode'
  #    on :n, :name,    '<NAME>'
  #    on :a, :age,     'Your age'
  #  end
  #  -------
  #  program.rb --verbose -n 'Emily' -a 25
  # @see Slop#banner
  # @see Slop#option
  def self.parse(items=ARGV, options={}, &block)
    initialize_and_parse(items, false, options, &block)
  end

  # Identical to {Slop.parse}, but removes parsed options from the original Array.
  #
  # @yield Specify available CLI arguments using Slop# methods such as Slop#banner and Slop#option
  # @return [Slop] Returns an instance of Slop.
  def self.parse!(items=ARGV, options={}, &block)
    initialize_and_parse(items, true, options, &block)
  end

  # @return [Options]
  attr_reader :options

  attr_writer :banner
  attr_accessor :longest_flag

  # @param [Hash] options
  # @option options [Boolean] :help Automatically add the `help` option
  # @option options [Boolean] :strict Strict mode raises when a non listed
  #   option is found, false by default
  def initialize(options={}, &block)
    @options = Options.new
    @banner = nil
    @longest_flag = 0
    @strict = options[:strict]
    @invalid_options = []

    if block_given?
      block.arity == 1 ? yield(self) : instance_eval(&block)
    end

    if options[:help]
      on :h, :help, 'Print this help message', :tail => true do
        puts help
        exit
      end
    end
  end

  # Set or return banner text.
  #
  # @param [String] text Displayed banner text.
  # @return [String] Returns current banner.
  # @example
  #   opts = Slop.parse do
  #     banner "Usage - ruby foo.rb [arguments]"
  #   end
  # @see Slop#to_s
  def banner(text=nil)
    @banner = text if text
    @banner
  end

  # Parse a list of options, leaving the original Array unchanged.
  #
  # @param items
  def parse(items=ARGV, &block)
    parse_items items, &block
  end

  # Parse a list of options, removing parsed options from the original Array.
  #
  # @param items
  def parse!(items=ARGV, &block)
    parse_items items, true, &block
  end

  # Enumerable interface
  def each
    return enum_for(:each) unless block_given?
    @options.each { |option| yield option }
  end

  # Return the value of an option via the subscript operator.
  #
  # @param [Symbol] key Option symbol.
  # @return [Object] Returns the object associated with that option.
  # @example
  #   opts[:name]
  #   #=> "Emily"
  # @see Slop#method_missing
  def [](key)
    option = @options[key]
    option.argument_value if option
  end

  # Specify an option with a short or long version, description and type.
  #
  # @param [*] args Option configuration.
  # @option args [Symbol, String] :short_flag Short option name.
{'fraction_non_alphanumeric': 0.10180823583042091, 'fraction_numerical': 0.001215620726333384, 'mean_word_length': 3.1344221105527637, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, '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': '1587244', 'n_tokens_mistral': 2151, 'n_tokens_neox': 2074, 'n_words': 740}