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

class Slop
  include Enumerable

  # Raised when an option expects an argument and none is given
  class MissingArgumentError < RuntimeError; end

  # Raised when an option specifies the `:match` attribute and this
  # options argument does not match this regexp
  class InvalidArgumentError < RuntimeError; end

  # Raised when the `:strict` option is enabled and an unknown
  # or unspecified option is used
  class InvalidOptionError < RuntimeError; end

  # @return [String] The current version string
  VERSION = '1.4.1'

  # Parses the items from a CLI format into a friendly object.
  #
  # @param [Array] items Items to parse into options.
  # @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
  # @return [Slop] Returns an instance of Slop.
  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.
  #
  # @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_reader :commands

  attr_writer :banner
  attr_accessor :longest_flag

  # @param [Hash] options
  # @option opts [Boolean] :help Automatically add the `help` option
  # @option opts [Boolean] :strict Strict mode raises when a non listed
  #   option is found, false by default
  # @option opts [Boolean] :multiple_switches Allows `-abc` to be processed
  #   as the options 'a', 'b', 'c' and will force their argument values to
  #   true. By default Slop with parse this as 'a' with the argument 'bc'
  def initialize(*opts, &block)
    sloptions = {}
    sloptions.merge! opts.pop if opts.last.is_a? Hash
    @banner = opts.shift if opts[0].respond_to?(:to_str)
    opts.each { |o| sloptions[o] = true }

    @options = Options.new
    @commands = {}
    @longest_flag = 0
    @strict = sloptions[:strict]
    @invalid_options = []
    @multiple_switches = sloptions[:multiple_switches]
    @on_empty = sloptions[:on_empty]
    @sloptions = sloptions

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

    if sloptions[: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.
  # @example
  #   opts = Slop.parse do
  #     banner "Usage - ruby foo.rb [arguments]"
  #   end
  # @return [String] Returns current banner.
  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.
  # @example
  #   opts[:name] #=> "Emily"
  # @return [Object] Returns the value associated with that option.
  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.
  # @option args [Symbol, String] :long_flag Full option name.
  # @option args [String] :description Option description for use in Slop#help
  # @option args [Boolean] :argument Specifies whether a required option or not.
  # @option args [Hash] :options Optional option configurations.
  # @example
  #   opts = Slop.parse do
  #     on :n, :name, 'Your username', true # Required argument
  #     on :a, :age,  'Your age (optional)', :optional => true
  #     on :g, :gender, 'Your gender', :optional => false
  #     on :V, :verbose, 'Run in verbose mode', :default => true
  #     on :P, :people, 'Your friends', true, :as => Array
  #     on :h, :help, 'Print this help screen' do
  #       puts help
  #     end
  #   end
  # @return [Slop::Option]
  def option(*args, &block)
    options = args.pop if args.last.is_a?(Hash)
    options ||= {}

    short, long, desc, arg = clean_options(args)
    option = Option.new(self, short, long, desc, arg, options, &block)
    @options << option

    option
  end
  alias :opt :option
  alias :on :option

  def command(label, options={}, &block)<commit_msg>add some documentation<commit_after>require 'slop/options'
require 'slop/option'

class Slop
  include Enumerable

  # Raised when an option expects an argument and none is given
  class MissingArgumentError < RuntimeError; end

  # Raised when an option specifies the `:match` attribute and this
  # options argument does not match this regexp
  class InvalidArgumentError < RuntimeError; end

  # Raised when the `:strict` option is enabled and an unknown
  # or unspecified option is used
  class InvalidOptionError < RuntimeError; end

  # @return [String] The current version string
  VERSION = '1.4.1'

  # Parses the items from a CLI format into a friendly object.
  #
  # @param [Array] items Items to parse into options.
  # @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
  # @return [Slop] Returns an instance of Slop.
  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.
  #
  # @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

  # @return [Hash]
  attr_reader :commands

  attr_writer :banner
  attr_accessor :longest_flag

  # @param [Hash] options
  # @option opts [Boolean] :help Automatically add the `help` option
  # @option opts [Boolean] :strict Strict mode raises when a non listed
  #   option is found, false by default
  # @option opts [Boolean] :multiple_switches Allows `-abc` to be processed
  #   as the options 'a', 'b', 'c' and will force their argument values to
  #   true. By default Slop with parse this as 'a' with the argument 'bc'
  def initialize(*opts, &block)
    sloptions = {}
    sloptions.merge! opts.pop if opts.last.is_a? Hash
    @banner = opts.shift if opts[0].respond_to?(:to_str)
    opts.each { |o| sloptions[o] = true }

    @options = Options.new
    @commands = {}
    @longest_flag = 0
    @strict = sloptions[:strict]
    @invalid_options = []
    @multiple_switches = sloptions[:multiple_switches]
    @on_empty = sloptions[:on_empty]
    @sloptions = sloptions

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

    if sloptions[: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.
  # @example
  #   opts = Slop.parse do
  #     banner "Usage - ruby foo.rb [arguments]"
  #   end
  # @return [String] Returns current banner.
  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.
  # @example
  #   opts[:name] #=> "Emily"
  # @return [Object] Returns the value associated with that option.
  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.
  # @option args [Symbol, String] :long_flag Full option name.
  # @option args [String] :description Option description for use in Slop#help
  # @option args [Boolean] :argument Specifies whether a required option or not.
  # @option args [Hash] :options Optional option configurations.
  # @example
  #   opts = Slop.parse do
  #     on :n, :name, 'Your username', true # Required argument
  #     on :a, :age,  'Your age (optional)', :optional => true
  #     on :g, :gender, 'Your gender', :optional => false
  #     on :V, :verbose, 'Run in verbose mode', :default => true
  #     on :P, :people, 'Your friends', true, :as => Array
  #     on :h, :help, 'Print this help screen' do
  #       puts help
  #     end
  #   end
  # @return [Slop::Option]
  def option(*args, &block)
    options = args.pop if args.last.is_a?(Hash)
    options ||= {}

    short, long, desc, arg = clean_options(args)
    option = Option.new(self, short, long, desc, arg, options, &block)
    @options << option

    option
  end
  alias :opt :option
  alias :on :option


  # Namespace options depending on what command is executed
  #
  # @param [Symbol, String] label
  # @param [Hash] options
  # @example
  #   opts = Slop.new do
  #     command :create do
  #       on :v, :verbose
  #     end
  #   end
  #
  #   # ARGV is `create -v`
  #   opts.commands[:create].verbose? #=> true
  # @return [Slop] a new instance of Slop namespaced to +label+
  def command(label, options={}, &block)
{'fraction_non_alphanumeric': 0.11020881670533643, 'fraction_numerical': 0.0015467904098994587, 'mean_word_length': 3.0824782951854774, 'pattern_counts': {'":': 0, '<': 14, '<?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': '3768851', 'n_tokens_mistral': 3354, 'n_tokens_neox': 3254, 'n_words': 1187}