From d2f03406266024b6ef02085eb32301263ab14f2a Mon Sep 17 00:00:00 2001 From: John Rogers Date: Sun, 17 Aug 2025 14:25:35 +0100 Subject: [PATCH] feat: create default config on first run Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) --- config.toml | 7 +++++++ src/main.rs | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 config.toml diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..4ce1ced --- /dev/null +++ b/config.toml @@ -0,0 +1,7 @@ +# Default configuration for jamdl +# Please edit these values to match your setup. + +nas_host = "localhost" +nas_user = "your_ssh_user" +nas_path = "/path/on/nas" +cookies_file = "/path/to/your/apple-music-cookies-file.txt" diff --git a/src/main.rs b/src/main.rs index b37a47f..7c89e2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use anyhow::{Context, Result}; use clap::Parser; use serde::Deserialize; use std::fs; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::process::Command; use tempfile::TempDir; @@ -25,15 +25,24 @@ struct Args { fn main() -> Result<()> { let args = Args::parse(); - let config_path = dirs::config_dir() + let config_dir = dirs::config_dir() .context("Could not find config directory")? - .join("jamdl/config.toml"); + .join("jamdl"); + let config_path = config_dir.join("config.toml"); if !config_path.exists() { - anyhow::bail!( - "Config file not found. Please create it at: {}", + println!("[INFO] No config file found, creating a default one..."); + fs::create_dir_all(&config_dir).context("Failed to create config directory")?; + + let default_config = include_str!("../config.toml"); + fs::write(&config_path, default_config).context("Failed to write default config file")?; + + println!( + "[INFO] A default config file was created at: {}", config_path.display() ); + println!("[INFO] Please edit this file with your settings and re-run the command."); + return Ok(()); } let settings = config::Config::builder()