<commit_before>require 'optparse'
require 'highline/import'

module Vmail
  class Options
    DEFAULT_CONTACTS_FILENAME = "vmail-contacts.txt"
    attr_accessor :config
    attr_accessor :contacts_file
    def initialize(argv)
      config_file_locations = ['.vmailrc', "#{ENV['HOME']}/.vmailrc"]
      @config_file = config_file_locations.detect do |path|
        File.exists?(File.expand_path(path))
      end
      @contacts_file = [DEFAULT_CONTACTS_FILENAME, "#{ENV['HOME']}/#{DEFAULT_CONTACTS_FILENAME}"].detect  do |path|
        File.exists?(File.expand_path(path))
      end
      @config = {}
      parse argv
    end

    def parse(argv)
      OptionParser.new do |opts|
        opts.banner = "Usage:  vmail [ options ] [ limit ] [ imap search query ]" 
        opts.separator ""
        opts.separator "Specific options:"
        opts.on("-c", "--config path", String, "Path to config file") do |config_file|
          @config_file = config_file
        end
        opts.on("-t", "--contacts path", String, "Path to contacts file") do |file|
          @contacts_file = file
        end
        opts.on("-g[n]", "--getcontacts[n]", Integer, "Generate contacts file. n is number of emails to scan (default 500).") do |n| 
          @get_contacts = true
          @max_messages_to_scan = n || 500
        end
        opts.on("-h", "--help", "Show this message") do
          puts opts
          exit
        end
        opts.separator ""
        opts.separator INSTRUCTIONS

        begin
          opts.parse!(argv)
          if @config_file && File.exists?(@config_file)
            puts "Using config file #{@config_file}"
          else
            puts <<EOF

Missing config file! 

#{INSTRUCTIONS}
EOF
            exit(1)
          end

          if @contacts_file.nil?
            puts "No contacts file found for auto-completion. See help for how to generate it."
            sleep 0.5<commit_msg>minor<commit_after>require 'optparse'
require 'highline/import'

module Vmail
  class Options
    DEFAULT_CONTACTS_FILENAME = "vmail-contacts.txt"
    attr_accessor :config
    attr_accessor :contacts_file
    def initialize(argv)
      config_file_locations = ['.vmailrc', "#{ENV['HOME']}/.vmailrc"]
      @config_file = config_file_locations.detect do |path|
        File.exists?(File.expand_path(path))
      end
      @contacts_file = [DEFAULT_CONTACTS_FILENAME, "#{ENV['HOME']}/#{DEFAULT_CONTACTS_FILENAME}"].detect  do |path|
        File.exists?(File.expand_path(path))
      end
      @config = {}
      parse argv
    end

    def parse(argv)
      OptionParser.new do |opts|
        opts.banner = "Usage:  vmail [ options ] [ limit ] [ imap search query ]" 
        opts.separator ""
        opts.separator "Specific options:"
        opts.on("-c", "--config path", String, "Path to config file") do |config_file|
          @config_file = config_file
        end
        opts.on("-t", "--contacts path", String, "Path to contacts file") do |file|
          @contacts_file = file
        end
        opts.on("-g[n]", "--getcontacts[n]", Integer, "Generate contacts file. n is number of emails to scan (default 500).") do |n| 
          @get_contacts = true
          @max_messages_to_scan = n || 500
        end
        opts.on("-h", "--help", "Show this message") do
          puts opts
          exit
        end
        opts.separator ""
        opts.separator INSTRUCTIONS

        begin
          opts.parse!(argv)
          if @config_file && File.exists?(@config_file)
            puts "Using config file #{@config_file}"
          else
            puts <<EOF

Missing config file! 

#{INSTRUCTIONS}
EOF
            exit(1)
          end

          if @contacts_file.nil?
            puts "No contacts file found for auto-completion. See help for how to generate it."
            sleep 0.5
          else
            puts "Using contacts file #{@contacts_file}"

{'fraction_non_alphanumeric': 0.11667951683371884, 'fraction_numerical': 0.004626060138781804, 'mean_word_length': 2.1642276422764226, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5732100', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1163, 'n_words': 311}