- Introduce `config` command for config file management - Add global options for Sonarr URL and API key - Implement `--monitored` filter for listing series - Add default TUI startup behavior
94 lines
2.0 KiB
Rust
94 lines
2.0 KiB
Rust
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<PathBuf>,
|
|
|
|
/// Sonarr URL (overrides config file)
|
|
#[arg(long, global = true, env = "YARR_SONARR_URL")]
|
|
pub sonarr_url: Option<String>,
|
|
|
|
/// Sonarr API key (overrides config file)
|
|
#[arg(long, global = true, env = "YARR_SONARR_API_KEY")]
|
|
pub sonarr_api_key: Option<String>,
|
|
|
|
#[command(subcommand)]
|
|
pub command: Option<Commands>,
|
|
}
|
|
|
|
#[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<PathBuf>,
|
|
},
|
|
|
|
/// Show possible config file locations
|
|
Paths,
|
|
}
|
|
|
|
impl Cli {
|
|
pub fn generate_completions(shell: clap_complete::Shell) {
|
|
let mut command = <Cli as clap::CommandFactory>::command();
|
|
clap_complete::generate(
|
|
shell,
|
|
&mut command,
|
|
env!("CARGO_BIN_NAME"),
|
|
&mut std::io::stdout(),
|
|
);
|
|
}
|
|
}
|