<commit_before>package config

import exception.ConfigurationNotSetupException

import java.nio.file.Path

/**
 * Load configuration.
 * Create a sample config if none present
 */
class ConfigLoader {

    Path configPath
    @Delegate ConfigObject config

    ConfigLoader(configPath) {
        this.configPath = configPath
        loadConfig()
    }

    private loadConfig() {
        failIfConfigFileDoesntExist()
        def slurper = new ConfigSlurper()
        def url = configPath.toUri().toURL()
        config = slurper.parse(url)
        failIfConfigFileNotCustomised()
    }

    private failIfConfigFileDoesntExist() {
        if (!configPath.toFile().exists()) {
            createSampleConfiguration()
            throwConfigurationException("Please customise configuration file at $configPath which has just been created")
        }
    }

    private failIfConfigFileNotCustomised() {
        if (config.isSet('deleteme')) {
            throwConfigurationException("Please customise configuration file at $configPath")
        }
    }

    private void throwConfigurationException(message) {
        println message
        throw new ConfigurationNotSetupException(message)
    }

    private createSampleConfiguration() {
        configPath.parent.toFile().mkdirs()
        File sampleConfig = configPath.toFile()
        sampleConfig.withWriter { out ->
            out.println 'darkskyapikey = "replace_this_with_api_key"'
            out.println 'slackurl = "replace_this_with_slack_url_for_incomming_message_hook"'
            out.println ''
            out.println 'deleteme = true    // Delete this line when you have finished'
        }
    }
}<commit_msg>Update sample for initial config file<commit_after>package config

import exception.ConfigurationNotSetupException

import java.nio.file.Path

/**
 * Load configuration.
 * Create a sample config if none present
 */
class ConfigLoader {

    Path configPath
    @Delegate ConfigObject config

    ConfigLoader(configPath) {
        this.configPath = configPath
        loadConfig()
    }

    private loadConfig() {
        failIfConfigFileDoesntExist()
        def slurper = new ConfigSlurper()
        def url = configPath.toUri().toURL()
        config = slurper.parse(url)
        failIfConfigFileNotCustomised()
    }

    private failIfConfigFileDoesntExist() {
        if (!configPath.toFile().exists()) {
            createSampleConfiguration()
            throwConfigurationException("Please customise configuration file at $configPath which has just been created")
        }
    }

    private failIfConfigFileNotCustomised() {
        if (config.isSet('deleteme')) {
            throwConfigurationException("Please customise configuration file at $configPath")
        }
    }

    private void throwConfigurationException(message) {
        println message
        throw new ConfigurationNotSetupException(message)
    }

    private createSampleConfiguration() {
        configPath.parent.toFile().mkdirs()
        File sampleConfig = configPath.toFile()
        sampleConfig.withWriter { out ->
            out.println 'darkskyapikey = "replace_this_with_api_key"'
            out.println 'slackurl = "replace_this_with_slack_url_for_incomming_message_hook"'
            out.println 'slackchannel = "replace_this_with_slack_channel_including_the_#_prefix"'
            out.println ''
            out.println 'deleteme = true    // Delete this line when you have finished'
        }
    }
}
{'fraction_non_alphanumeric': 0.07950631458094144, 'fraction_numerical': 0.0, 'mean_word_length': 2.7757313109425787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5552467', 'n_tokens_mistral': 917, 'n_tokens_neox': 894, 'n_words': 204}