<commit_before>require "yaml"

module Muzak
  module Cmd
    def _config_available?
      File.file?(CONFIG_FILE)
    end

    def _config_loaded?
      !!@config
    end

    def _config_sync
      debug "syncing config hash with #{CONFIG_FILE}"
      File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
    end

    def _config_init
      debug "creating a config file in #{CONFIG_FILE}"

      @config = {
        "music" => File.expand_path("~/music"),
        "player" => "mpv",
        "index-autobuild" => 86400,
        "deep-index" => false
      }

      Dir.mkdir(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
      _config_sync
    end

    def _config_plugin?(name)
      @config.key?("plugin-#{name}")
    end

    def config_load
      verbose "loading config from #{CONFIG_FILE}"

      @config = YAML::load_file(CONFIG_FILE)
    end

    def config_get(*args)
      return unless _config_loaded?

      fail_arity(args, 1)
      key = args.shift<commit_msg>cmd/config: Add a default jukebox-size (100).<commit_after>require "yaml"

module Muzak
  module Cmd
    def _config_available?
      File.file?(CONFIG_FILE)
    end

    def _config_loaded?
      !!@config
    end

    def _config_sync
      debug "syncing config hash with #{CONFIG_FILE}"
      File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml }
    end

    def _config_init
      debug "creating a config file in #{CONFIG_FILE}"

      @config = {
        "music" => File.expand_path("~/music"),
        "player" => "mpv",
        "index-autobuild" => 86400,
        "deep-index" => false,
        "jukebox-size" => 100
      }

      Dir.mkdir(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
      _config_sync
    end

    def _config_plugin?(name)
      @config.key?("plugin-#{name}")
    end

    def config_load
      verbose "loading config from #{CONFIG_FILE}"

      @config = YAML::load_file(CONFIG_FILE)
    end

    def config_get(*args)
      return unless _config_loaded?

      fail_arity(args, 1)
      key = args.shift
{'fraction_non_alphanumeric': 0.1166584280771132, 'fraction_numerical': 0.008897676717745922, 'mean_word_length': 2.436332767402377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '1037591', 'n_tokens_mistral': 704, 'n_tokens_neox': 668, 'n_words': 154}