<commit_before>use super::dirs::dir_config_create;
use super::error::WrapConfigError;

extern crate config;
use self::config::reader::from_file;
use self::config::types::{Config, SettingsList};

use std::error::Error;
use std::fs::metadata;
use std::path::Path;

// Fix this craziness. Waiting on https://github.com/filipegoncalves/rust-config/issues/2.
fn wrap_from_file(path: &Path) -> Result<Config, WrapConfigError> {
    Ok(try!(from_file(path)))
}

pub fn load_config(app: &str, file: &str) -> Result<Config, Box<Error>> {
    let mut path_buf = try!(dir_config_create(app));
    path_buf.push(file);
    let path = path_buf.as_path();

    if metadata(path).ok().map_or(false, |m| m.is_file()) {
        let config = try!(wrap_from_file(path));
        Ok(config)
    } else {
        Ok(Config::new(SettingsList::new()))
    }
}<commit_msg>config: add function taking a direct path<commit_after>use super::dirs::dir_config_create;
use super::error::WrapConfigError;

extern crate config;
use self::config::reader::from_file;
use self::config::types::{Config, SettingsList};

use std::error::Error;
use std::fs::metadata;
use std::path::Path;

// Fix this craziness. Waiting on https://github.com/filipegoncalves/rust-config/issues/2.
fn wrap_from_file(path: &Path) -> Result<Config, WrapConfigError> {
    Ok(try!(from_file(path)))
}

pub fn load_config(app: &str, file: &str) -> Result<Config, Box<Error>> {
    let mut path_buf = try!(dir_config_create(app));
    path_buf.push(file);

    load_config_path(path_buf.as_path())
}

pub fn load_config_path(path: &Path) -> Result<Config, Box<Error>> {
    if metadata(path).ok().map_or(false, |m| m.is_file()) {
        let config = try!(wrap_from_file(path));
        Ok(config)
    } else {
        Ok(Config::new(SettingsList::new()))
    }
}
{'fraction_non_alphanumeric': 0.16981132075471697, 'fraction_numerical': 0.0011098779134295228, 'mean_word_length': 4.911475409836066, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, 'https://': 2, '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': '6291663', 'n_tokens_mistral': 630, 'n_tokens_neox': 628, 'n_words': 122}