<commit_before>require 'voog/dtk/version'
require 'parseconfig'
require 'prettyprint'

module Voog
  module Dtk

    CONFIG_FILENAME = '.voog'

    class << self
      def config_exists?(filename=CONFIG_FILENAME)
        filename && !filename.empty? && File.exist?(filename)
      end

      def global_config_exists?(filename=CONFIG_FILENAME)
        filename && !filename.empty? && File.exist?([ENV['HOME'], filename].join('/'))
      end

      def read_config(block = nil, file = CONFIG_FILENAME)
        config = {
          :host => nil,
          :api_token => <PASSWORD>,
          :overwrite => false
        }
        local_config = config_exists?(file) ? ParseConfig.new(File.expand_path(file)).params : {}
        global_config = global_config_exists?(file) ? ParseConfig.new(File.expand_path([ENV['HOME'], file].join('/'))).params : {}

        options = global_config.merge(local_config)

        unless options.empty?
          @block = if block.nil?
            options.keys.first
          else
            if options.key?(block)
              block
            else
              fail "Site '#{block}' not found in the configuration file!".red<commit_msg>Prefer local config over global config when looking for default host/token.<commit_after>require 'voog/dtk/version'
require 'parseconfig'
require 'prettyprint'

module Voog
  module Dtk

    CONFIG_FILENAME = '.voog'

    class << self
      def config_exists?(filename=CONFIG_FILENAME)
        filename && !filename.empty? && File.exist?(filename)
      end

      def global_config_exists?(filename=CONFIG_FILENAME)
        filename && !filename.empty? && File.exist?([ENV['HOME'], filename].join('/'))
      end

      def read_config(block = nil, file = CONFIG_FILENAME)
        config = {
          :host => nil,
          :api_token => nil,
          :overwrite => false
        }
        local_config = config_exists?(file) ? ParseConfig.new(File.expand_path(file)).params : {}
        global_config = global_config_exists?(file) ? ParseConfig.new(File.expand_path([ENV['HOME'], file].join('/'))).params : {}

        options = local_config.merge(global_config)

        unless options.empty?
          @block = if block.nil?
            options.keys.first
          else
            if options.key?(block)
              block
            else
              fail "Site '#{block}' not found in the configuration file!".red
{'fraction_non_alphanumeric': 0.1241149521032903, 'fraction_numerical': 0.0, 'mean_word_length': 2.466089466089466, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, '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': '3342325', 'n_tokens_mistral': 684, 'n_tokens_neox': 673, 'n_words': 145}