use error::{Result, ResultExt};
use serde_json::{self, Value};
use std::env;
use std::fs::File;
use std::path::{Path, PathBuf};
pub fn path() -> Result<PathBuf> {
let mut path = env::current_dir()
.chain_err(|| "coudln't get current directory")?;
loop {
path.push("leven.json");
if path.is_file() {
return Ok(path);
}
path.pop();
if !path.pop() {
return Err("no 'leven.json' found".into());
}
}
}
pub fn parse(path: &Path) -> Result<Value> {
let file = File::open(path)
.chain_err(|| "couldn't open config")?;
serde_json::from_reader(file)
.chain_err(|| "bad config")
}