<commit_before>require "optparse_plus/version"
require 'optparse'
require 'yaml'
require 'ripper'

module OptparsePlus
  attr_reader :opt_plus

  module ClassMethods
    def read_after_program_end(cur_file)
      own_source = File.read(cur_file)
      last_token = Ripper.lex(own_source)[-1]
      return nil unless last_token[1] == :on___end__
      start = last_token[0][0]
      own_source.lines[start..-1].join
    end

    def new_with_yaml(config_yaml_source=nil)
      cur_file = caller[0].split(/:/)[0]
      config_yaml_source ||= read_after_program_end(cur_file)
      opt_plus = OptPlus.new(config_yaml_source)
      if banner = opt_plus.config["banner"]
        opt = ::OptionParser.new(banner)
      else
        opt = ::OptionParser.new
      end

      opt.setup_opt_plus(opt_plus)

      if block_given?
        yield opt
      else
        opt
      end
    end
  end

  class OptPlus
    attr_reader :config, :config_source, :callbacks
    attr_writer :opt

    def initialize(config_yaml_source)
      @config_source = config_yaml_source
      @config = YAML.load(config_yaml_source)
      @callbacks = {}
      @opt = nil
    end

    def opt_on
      @callbacks.keys.each {|label| reflect_callback(label) }
    end

    def reflect_callback(label)
      label = label
      callback = @callbacks[label]
      options = @config[label.to_s]
      args = %w(short long desc).map {|type| options[type] }
        .select {|option| not option.nil? }.flatten
      @opt.on(*args, callback)
    end
  end

  def with(option_label, &callback)
    @opt_plus.callbacks[option_label] = callback
  end

  def parse!
    @opt_plus.opt_on
    super
  end

  def setup_opt_plus(opt_plus)
    @opt_plus = opt_plus
    opt_plus.opt = self
  end
end

class OptionParser
  prepend OptparsePlus
  extend OptparsePlus::ClassMethods
end<commit_msg>set the visibility of OptionParser.read_after_program_end to private<commit_after>require "optparse_plus/version"
require 'optparse'
require 'yaml'
require 'ripper'

module OptparsePlus
  attr_reader :opt_plus

  module ClassMethods
    def read_after_program_end(cur_file)
      own_source = File.read(cur_file)
      last_token = Ripper.lex(own_source)[-1]
      return nil unless last_token[1] == :on___end__
      start = last_token[0][0]
      own_source.lines[start..-1].join
    end

    def new_with_yaml(config_yaml_source=nil)
      cur_file = caller[0].split(/:/)[0]
      config_yaml_source ||= read_after_program_end(cur_file)
      opt_plus = OptPlus.new(config_yaml_source)
      if banner = opt_plus.config["banner"]
        opt = ::OptionParser.new(banner)
      else
        opt = ::OptionParser.new
      end

      opt.setup_opt_plus(opt_plus)

      if block_given?
        yield opt
      else
        opt
      end
    end
  end

  class OptPlus
    attr_reader :config, :config_source, :callbacks
    attr_writer :opt

    def initialize(config_yaml_source)
      @config_source = config_yaml_source
      @config = YAML.load(config_yaml_source)
      @callbacks = {}
      @opt = nil
    end

    def opt_on
      @callbacks.keys.each {|label| reflect_callback(label) }
    end

    def reflect_callback(label)
      label = label
      callback = @callbacks[label]
      options = @config[label.to_s]
      args = %w(short long desc).map {|type| options[type] }
        .select {|option| not option.nil? }.flatten
      @opt.on(*args, callback)
    end
  end

  def with(option_label, &callback)
    @opt_plus.callbacks[option_label] = callback
  end

  def parse!
    @opt_plus.opt_on
    super
  end

  def setup_opt_plus(opt_plus)
    @opt_plus = opt_plus
    opt_plus.opt = self
  end
end

class OptionParser
  prepend OptparsePlus
  extend OptparsePlus::ClassMethods
  private_class_method :read_after_program_end
end
{'fraction_non_alphanumeric': 0.09172377438060095, 'fraction_numerical': 0.0036900369003690036, 'mean_word_length': 2.9204545454545454, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6096075', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1262, 'n_words': 265}