Skip to content

Commit

Permalink
Merge pull request #52 from AnthonyMichaelTDM/51-feat-if-config-data-…
Browse files Browse the repository at this point in the history
…path-is-missing-create-it

feat: Add default config file if it doesn't exist
  • Loading branch information
AnthonyMichaelTDM authored Jun 21, 2024
2 parents d260d6e + 012bc98 commit 2328305
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct Flags {
config: Option<PathBuf>,
}

static DEFAULT_CONFIG: &str = include_str!("../../Mecomp.toml");

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let flags = Flags::try_parse()?;
Expand All @@ -31,11 +33,19 @@ async fn main() -> anyhow::Result<()> {
Ok(config_dir) => config_dir.join("Mecomp.toml"),
Err(e) => {
eprintln!("Error: {e}");
// TODO: once this thing is released, maybe make this an actual error?
PathBuf::from("Mecomp.toml")
anyhow::bail!("Could not find the config directory")
}
};

if !config_file.exists() {
// create the directory if it doesn't exist
if let Some(parent) = config_file.parent() {
std::fs::create_dir_all(parent)?;
}
// write the default config file
std::fs::write(&config_file, DEFAULT_CONFIG)?;
}

let db_dir = match get_data_dir() {
Ok(data_dir) => data_dir.join("db"),
Err(e) => {
Expand Down

0 comments on commit 2328305

Please sign in to comment.