feat(cli): add config management and enhanced command options
- 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
This commit is contained in:
91
src/cli.rs
91
src/cli.rs
@@ -1,30 +1,87 @@
|
||||
#[derive(Debug, clap::Parser)]
|
||||
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 {
|
||||
#[clap(subcommand)]
|
||||
pub cmd: SubCommand,
|
||||
/// 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, clap::Subcommand)]
|
||||
pub enum SubCommand {
|
||||
#[clap(name = "add")]
|
||||
Add(Add),
|
||||
#[clap(name = "list")]
|
||||
List(List),
|
||||
#[clap(name = "completions")]
|
||||
Completions { shell: clap_complete::Shell },
|
||||
#[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, clap::Args)]
|
||||
pub struct Add {
|
||||
#[clap(short, long)]
|
||||
#[derive(Debug, Args)]
|
||||
pub struct AddArgs {
|
||||
/// Name of the series to add
|
||||
#[arg(short, long)]
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Args)]
|
||||
pub struct List {}
|
||||
#[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 completions(shell: clap_complete::Shell) {
|
||||
pub fn generate_completions(shell: clap_complete::Shell) {
|
||||
let mut command = <Cli as clap::CommandFactory>::command();
|
||||
clap_complete::generate(
|
||||
shell,
|
||||
|
||||
Reference in New Issue
Block a user