Skip to content

Commit

Permalink
Make inlyne config open reject invalid configs
Browse files Browse the repository at this point in the history
  • Loading branch information
kokoISnoTarget authored and CosmicHorrorDev committed Feb 2, 2025
1 parent db82c10 commit 79006d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,15 +808,20 @@ fn main() -> anyhow::Result<()> {
.join("inlyne")
.join("inlyne.toml");

if !config_path.is_file() {
tracing::warn!(
"No config found. Creating a new config at: {}",
config_path.display()
);
Config::create_default_config(&config_path)?;
}
let config = std::fs::read_to_string(&config_path)
.unwrap_or_else(|_| Config::default_config().to_string());

let new_config = edit::edit_with_builder(
&config,
edit::Builder::new()
.prefix("inlyne_temp")
.suffix(".toml")
.keep(true),
)?;

_ = Config::load_from_str(&new_config)?;

edit::edit_file(config_path)?;
std::fs::write(config_path, new_config)?;
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/opts/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@ impl Config {
)?;

let mut file = std::fs::File::create(path)?;
file.write_all(include_bytes!("../../inlyne.default.toml"))?;
file.write_all(Self::default_config().as_bytes())?;
Ok(())
}

pub const fn default_config() -> &'static str {
include_str!("../../inlyne.default.toml")
}
}

#[cfg(test)]
Expand Down

0 comments on commit 79006d1

Please # to comment.