<commit_before>require 'collins_client'
require 'highline/import'
require 'yaml'
require 'socket'

module Collins
  module Authenticator
    def self.setup_client(options = {})
      Collins::Client.new load_config(options)
    end

    def self.load_config options = {prompt: false}
      conf = (read_config || options) unless options[:prompt] == :only
      
      # check if we have all that we expect
      if [:username, :password, :host].all? {|key| conf.keys.include? key}
        return conf
      end
      
      # Something is missing. Can we prompt for it?
      if prompt
        conf.merge(prompt_creds(conf))
      else
        raise "could not load any valid configuration."
      end
      
      conf
    end
    
    private
    def self.file2conf(file)
      if file and File.readable? file
        # YAML config has keys as strings but we want symbols
        YAML.load_file(file).reduce({}) do |hash, (key, value)|
          hash[begin key.to_sym rescue key end] = value
          hash
        end<commit_msg>Make it nil by default<commit_after>require 'collins_client'
require 'highline/import'
require 'yaml'
require 'socket'

module Collins
  module Authenticator
    def self.setup_client(options = nil)
      Collins::Client.new load_config(options)
    end

    def self.load_config options = {prompt: false}
      conf = (read_config || options) unless options[:prompt] == :only
      
      # check if we have all that we expect
      if [:username, :password, :host].all? {|key| conf.keys.include? key}
        return conf
      end
      
      # Something is missing. Can we prompt for it?
      if prompt
        conf.merge(prompt_creds(conf))
      else
        raise "could not load any valid configuration."
      end
      
      conf
    end
    
    private
    def self.file2conf(file)
      if file and File.readable? file
        # YAML config has keys as strings but we want symbols
        YAML.load_file(file).reduce({}) do |hash, (key, value)|
          hash[begin key.to_sym rescue key end] = value
          hash
        end
{'fraction_non_alphanumeric': 0.08678881388621022, 'fraction_numerical': 0.0009643201542912247, 'mean_word_length': 2.3094098883572567, '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': '7311784', 'n_tokens_mistral': 608, 'n_tokens_neox': 594, 'n_words': 202}