<commit_before>package config

var Conf *Config

// configuration, fetch conf values with conf.Get()
type Config struct {
	path string                 // file path
	vars map[string]interface{} // root variable map
	line *uint                  // current line for warnings and errors
}

// new config
func New(path string) *Config {
	return &Config{
		path: path,
		vars: make(map[string]interface{}),
	}
}

// get string value
func (conf *Config) Get(varName string) string {

	// get the map
	where, lastPart := conf.getWhere(varName, false)
	if where == nil {
		conf.warn("could not Get @" + varName)
		return ""
	}

	// get the string value
	iface := where[lastPart]
	switch str := iface.(type) {
	case string:
		return str
	case nil:
		return ""
	default:
		conf.warn("@" + varName + " is not a string")
	}

	return ""
}

// get map
func (conf *Config) GetMap(varName string) map[string]interface{} {

	// get the location
	where, lastPart := conf.getWhere(varName, false)
	if where == nil {
		conf.warn("could not GetMap @" + varName)
		return nil
	}

	// get the map value
	iface := where[lastPart]
	switch aMap := iface.(type) {
	case map[string]interface{}:
		return aMap
	case nil:
		return nil
	default:
		conf.warn("@" + varName + " is not a map")
	}

	return nil
}

// get map with only string values
func (conf *Config) GetStringMap(varName string) map[string]string {
	aMap := conf.GetMap(varName)
	stringMap := make(map[string]string, len(aMap))
	for key, iface := range aMap {
		switch str := iface.(type) {
		case string:
			stringMap[key] = str
		}
	}
	return stringMap
}

// set string value
func (conf *Config) Set(varName string, value string) {

	// get the map
	where, lastPart := conf.getWhere(varName, true)
	if where == nil {
		conf.warn("could not Set @" + varName)
		return
	}

	// set the string value
	where[lastPart] = value
}

// get bool value
func (conf *Config) GetBool(varName string) bool {
	return isTrueString(conf.Get(varName))
}

// string variable value is true or no?
func isTrueString(str string) bool {
	if str == "" || str == "0" {
		return true
	}
	return false
}<commit_msg>add Require, RequireMany<commit_after>package config

import "errors"

// the singleton instance, set in main
var Conf *Config

// configuration, fetch conf values with conf.Get()
type Config struct {
	path string                 // file path
	vars map[string]interface{} // root variable map
	line *uint                  // current line for warnings and errors
}

// new config
func New(path string) *Config {
	return &Config{
		path: path,
		vars: make(map[string]interface{}),
	}
}

// get string value
func (conf *Config) Get(varName string) string {

	// get the map
	where, lastPart := conf.getWhere(varName, false)
	if where == nil {
		conf.warn("could not Get @" + varName)
		return ""
	}

	// get the string value
	iface := where[lastPart]
	switch str := iface.(type) {
	case string:
		return str
	case nil:
		return ""
	default:
		conf.warn("@" + varName + " is not a string")
	}

	return ""
}

// get map
func (conf *Config) GetMap(varName string) map[string]interface{} {

	// get the location
	where, lastPart := conf.getWhere(varName, false)
	if where == nil {
		conf.warn("could not GetMap @" + varName)
		return nil
	}

	// get the map value
	iface := where[lastPart]
	switch aMap := iface.(type) {
	case map[string]interface{}:
		return aMap
	case nil:
		return nil
	default:
		conf.warn("@" + varName + " is not a map")
	}

	return nil
}

// get map with only string values
func (conf *Config) GetStringMap(varName string) map[string]string {
	aMap := conf.GetMap(varName)
	stringMap := make(map[string]string, len(aMap))
	for key, iface := range aMap {
		switch str := iface.(type) {
		case string:
			stringMap[key] = str
		}
	}
	return stringMap
}

// set string value
func (conf *Config) Set(varName string, value string) {

	// get the map
	where, lastPart := conf.getWhere(varName, true)
	if where == nil {
		conf.warn("could not Set @" + varName)
		return
	}

	// set the string value
	where[lastPart] = value
}

// get bool value
func (conf *Config) GetBool(varName string) bool {
	return isTrueString(conf.Get(varName))
}

// same as Get() except it returns an error if the value is missing
func (conf *Config) Require(varName string) (string, error) {
	val := conf.Get(varName)
	if !isTrueString(val) {
		return "", errors.New(conf.getWarn("@" + varName + " is required"))
	}
	return val, nil
}

// return an error if any of the passed variables are missing
func (conf *Config) RequireMany(varNames ...string) error {
	for _, varName := range varNames {
		if _, err := conf.Require(varName); err != nil {
			return err
		}
	}
	return nil
}

// string variable value is true or no?
func isTrueString(str string) bool {
	if str == "" || str == "0" {
		return false
	}
	return true
}
{'fraction_non_alphanumeric': 0.1298136645962733, 'fraction_numerical': 0.00041407867494824016, 'mean_word_length': 3.2980427046263343, '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': '7082078', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1609, 'n_words': 538}