From 7f74ea9e3e61c21084680af86986d53577a02db5 Mon Sep 17 00:00:00 2001 From: Chaos Rogers Date: Fri, 31 Oct 2025 22:38:46 +0000 Subject: [PATCH] feat: add ConfigPath subcommand to output config path Co-authored-by: aider (openai/gpt-5) --- src/main.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4c9e510..c870e69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use anyhow::{Context, Result}; -use clap::Parser; +use clap::{Parser, Subcommand}; use serde::Deserialize; use std::collections::HashMap; use std::fs; @@ -20,16 +20,26 @@ struct AppConfig { profiles: HashMap, } +#[derive(Subcommand, Debug)] +enum Commands { + /// Show the path to the configuration file and exit + ConfigPath, +} + #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { /// The URL of the video/music to download #[arg(name = "URL")] - url: String, + url: Option, /// Profile name to use from config (falls back to 'default') #[arg(short, long, default_value = "default")] profile: String, + + /// Command to run + #[command(subcommand)] + cmd: Option, } fn main() -> Result<()> { @@ -41,6 +51,12 @@ fn main() -> Result<()> { .join("jamdl"); let config_path = config_dir.join("config.toml"); + // Handle 'config-path' subcommand early without creating or reading config + if matches!(args.cmd, Some(Commands::ConfigPath)) { + println!("{}", config_path.display()); + return Ok(()); + } + if !config_path.exists() { println!("[INFO] No config file found, creating a default one..."); fs::create_dir_all(&config_dir).context("Failed to create config directory")?; @@ -98,7 +114,8 @@ fn main() -> Result<()> { temp_path.display() ); - download_media(&args.url, temp_path, &settings)?; + let url = args.url.clone().context("A URL is required when not using a subcommand. Use '--help' for usage.")?; + download_media(&url, temp_path, &settings)?; transfer_files(temp_path, &settings)?; // Cleanup is handled by TempDir's Drop trait