feat: add ConfigPath subcommand to output config path

Co-authored-by: aider (openai/gpt-5) <aider@aider.chat>
This commit is contained in:
Chaos Rogers 2025-10-31 22:38:46 +00:00
parent 53bbfd9501
commit 7f74ea9e3e

View file

@ -1,5 +1,5 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser; use clap::{Parser, Subcommand};
use serde::Deserialize; use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs; use std::fs;
@ -20,16 +20,26 @@ struct AppConfig {
profiles: HashMap<String, Settings>, profiles: HashMap<String, Settings>,
} }
#[derive(Subcommand, Debug)]
enum Commands {
/// Show the path to the configuration file and exit
ConfigPath,
}
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
struct Args { struct Args {
/// The URL of the video/music to download /// The URL of the video/music to download
#[arg(name = "URL")] #[arg(name = "URL")]
url: String, url: Option<String>,
/// Profile name to use from config (falls back to 'default') /// Profile name to use from config (falls back to 'default')
#[arg(short, long, default_value = "default")] #[arg(short, long, default_value = "default")]
profile: String, profile: String,
/// Command to run
#[command(subcommand)]
cmd: Option<Commands>,
} }
fn main() -> Result<()> { fn main() -> Result<()> {
@ -41,6 +51,12 @@ fn main() -> Result<()> {
.join("jamdl"); .join("jamdl");
let config_path = config_dir.join("config.toml"); 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() { if !config_path.exists() {
println!("[INFO] No config file found, creating a default one..."); println!("[INFO] No config file found, creating a default one...");
fs::create_dir_all(&config_dir).context("Failed to create config directory")?; fs::create_dir_all(&config_dir).context("Failed to create config directory")?;
@ -98,7 +114,8 @@ fn main() -> Result<()> {
temp_path.display() 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)?; transfer_files(temp_path, &settings)?;
// Cleanup is handled by TempDir's Drop trait // Cleanup is handled by TempDir's Drop trait