feat: create default config on first run

Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
Chaos Rogers 2025-08-17 14:25:35 +01:00
parent c740e0df0e
commit d2f0340626
2 changed files with 21 additions and 5 deletions

7
config.toml Normal file
View file

@ -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"

View file

@ -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()