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

class Slop
  include Enumerable

  class MissingArgumentError < ArgumentError; end

  def self.parse(items=ARGV, &block)
    slop = new(&block)
    slop.parse(items)
    slop
  end

  attr_reader :options

  def initialize(&block)
    @options = Options.new

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

  def parse(items=ARGV)
    parse_items(items)
  end

  def parse!(items=ARGV)
    parse_items(items, true)
  end

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

  def [](key)
    key = key.to_s
    option = @options.find do |opt|
      opt.short_flag == key || opt.long_flag == key
    end
    option ? option.argument_value : nil
  end

  # :short_flag
  # :long_flag
  # :description
  # :argument
  def option(*args, &block)
    options = args.pop if args.last.is_a?(Hash)
    options ||= {}

    option = Option.new(*clean_options(args), options, &block)
    @options << option

    option
  end
  alias :opt :option<commit_msg>Slop#[] can now use Options#[]<commit_after>require 'slop/option'
require 'slop/version'

class Slop
  include Enumerable

  class MissingArgumentError < ArgumentError; end

  def self.parse(items=ARGV, &block)
    slop = new(&block)
    slop.parse(items)
    slop
  end

  attr_reader :options

  def initialize(&block)
    @options = Options.new

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

  def parse(items=ARGV)
    parse_items(items)
  end

  def parse!(items=ARGV)
    parse_items(items, true)
  end

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

  def [](key)
    option = @options[key]
    option ? option.argument_value : nil
  end

  # :short_flag
  # :long_flag
  # :description
  # :argument
  def option(*args, &block)
    options = args.pop if args.last.is_a?(Hash)
    options ||= {}

    option = Option.new(*clean_options(args), options, &block)
    @options << option

    option
  end
  alias :opt :option
{'fraction_non_alphanumeric': 0.11313039527487506, 'fraction_numerical': 0.0009086778736937755, 'mean_word_length': 3.077777777777778, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '4347247', 'n_tokens_mistral': 774, 'n_tokens_neox': 739, 'n_words': 186}