use std::fs;
use std::path::PathBuf;
use super::error::{ConfigError, IoResultExt};
use super::load::{default_config_toml, home_dir};
pub fn init_config_path() -> PathBuf {
home_dir()
.map(|h| h.join(".lxconfig.toml"))
.unwrap_or_else(|| PathBuf::from(".lxconfig.toml"))
}
pub fn write_init_config(path: &PathBuf) -> Result<(), ConfigError> {
if path.exists() {
let err = std::io::Error::other("already exists; remove it first or edit it directly");
return Err(err).with_path(path);
}
fs::write(path, default_config_toml()).with_path(path)
}