use clap::{Args, Parser, Subcommand}; use std::path::PathBuf; #[derive(Debug, Parser)] #[command(name = "yarr")] #[command(about = "A TUI for managing Sonarr")] #[command(version)] pub struct Cli { /// Path to config file #[arg(short, long, global = true)] pub config: Option, /// Sonarr URL (overrides config file) #[arg(long, global = true, env = "YARR_SONARR_URL")] pub sonarr_url: Option, /// Sonarr API key (overrides config file) #[arg(long, global = true, env = "YARR_SONARR_API_KEY")] pub sonarr_api_key: Option, #[command(subcommand)] pub command: Option, } #[derive(Debug, Subcommand)] pub enum Commands { /// Add a new series Add(AddArgs), /// List series List(ListArgs), /// Start the TUI interface (default) Tui, /// Generate shell completions Completions { /// The shell to generate completions for #[arg(value_enum)] shell: clap_complete::Shell, }, /// Configuration management Config(ConfigArgs), } #[derive(Debug, Args)] pub struct AddArgs { /// Name of the series to add #[arg(short, long)] pub name: String, } #[derive(Debug, Args)] pub struct ListArgs { /// Show only monitored series #[arg(short, long)] pub monitored: bool, } #[derive(Debug, Args)] pub struct ConfigArgs { #[command(subcommand)] pub action: ConfigAction, } #[derive(Debug, Subcommand)] pub enum ConfigAction { /// Show current configuration Show, /// Create a sample config file Init { /// Path where to create the config file #[arg(short, long)] path: Option, }, /// Show possible config file locations Paths, } impl Cli { pub fn generate_completions(shell: clap_complete::Shell) { let mut command = ::command(); clap_complete::generate( shell, &mut command, env!("CARGO_BIN_NAME"), &mut std::io::stdout(), ); } }