diff options
author | Canop <cano.petrole@gmail.com> | 2022-07-04 20:49:55 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2022-07-04 20:49:55 +0200 |
commit | 5666e6b9fb827c07c6c21fbe0fc60f538e1aaf60 (patch) | |
tree | c5e271b91edcde4da7dcfd8f0d9f0899ca2a16bd /src/conf/conf.rs | |
parent | c688a083b46628f1a9c7a23d1765016177514be4 (diff) |
default conf is now a directory
and not just a file, thanks to imports. And it contains
skin files.
Fix #431
Fix #340
Diffstat (limited to 'src/conf/conf.rs')
-rw-r--r-- | src/conf/conf.rs | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/src/conf/conf.rs b/src/conf/conf.rs index 1fe2df0..4ccd302 100644 --- a/src/conf/conf.rs +++ b/src/conf/conf.rs @@ -19,10 +19,7 @@ use { crossterm::style::Attribute, fnv::FnvHashMap, serde::Deserialize, - std::{ - fs, io, - path::{Path, PathBuf}, - }, + std::path::PathBuf, }; macro_rules! overwrite { @@ -127,29 +124,23 @@ impl Conf { /// read the configuration file from the default OS specific location. /// Create it if it doesn't exist pub fn from_default_location() -> Result<Conf, ProgramError> { + let conf_dir = super::dir(); let conf_filepath = Conf::default_location(); if !conf_filepath.exists() { - Conf::write_sample(&conf_filepath)?; + write_default_conf_in(conf_dir)?; println!( - "New Configuration file written in {}{:?}{}.", + "New Configuration files written in {}{:?}{}.", Attribute::Bold, - &conf_filepath, + &conf_dir, Attribute::Reset, ); - println!("You should have a look at it."); + println!("You should have a look at them."); } let mut conf = Conf::default(); - conf.read_file(conf_filepath.clone())?; + conf.read_file(conf_filepath)?; Ok(conf) } - /// assume the file doesn't yet exist - pub fn write_sample(filepath: &Path) -> Result<(), io::Error> { - fs::create_dir_all(filepath.parent().unwrap())?; - fs::write(filepath, DEFAULT_CONF_FILE)?; - Ok(()) - } - pub fn solve_conf_path(&self, path: &str) -> Option<PathBuf> { if path.ends_with(".toml") || path.ends_with(".hjson") { for conf_file in self.files.iter().rev() { |