Promote Route::Readarr from a unit stub to a tuple variant and wire Readarr through every layer, mirroring the Lidarr tree. Readarr appears as a fourth servarr tab and its library view renders the Authors table. Adds ReadarrData and its modals, the tick and context clue modules, the top-level ReadarrHandler, ReadarrUi with the Authors library view, and an empty ReadarrCommand behind ReadarrCliHandler. The default port is 8787. Promoting the route variant compiles cleanly without any of the arms that give it behaviour, so all six of those sites are wired explicitly here: App::on_tick, handlers::handle_events, handle_prompt_toggle, ServarrContextClueProvider, ui(), and verify_config_present_for_cli. Each was checked by removing the arm and confirming its covering assertion then fails. ReadarrEvent and ReadarrCommand are both declared empty. They gain variants alongside the network calls and CLI commands that use them, which keeps each later change to a single function. Adding the tab changes the rendered tab bar, so 13 existing snapshots regenerate. The only delta in each is that single tab bar line. This scaffold adds 24 dead_code warnings, all inside the Readarr tree and none outside it. They clear as the handlers, UI, network events, and CLI commands that consume these items land: block arrays awaiting their accepts implementations and BlockSelectionState seeding, modal and state fields awaiting their handlers, the CLI handler fields awaiting an inhabited command enum, and the top-level handler fields awaiting sub-handlers. The count must strictly decrease from here, so a later increase is a defect rather than transient noise. The 12 pre-existing collapsible_match warnings are unrelated and untouched.
118 lines
2.8 KiB
Rust
118 lines
2.8 KiB
Rust
use std::sync::Arc;
|
|
|
|
use anyhow::Result;
|
|
use clap::Subcommand;
|
|
use clap_complete::Shell;
|
|
use indoc::indoc;
|
|
use lidarr::{LidarrCliHandler, LidarrCommand};
|
|
use radarr::{RadarrCliHandler, RadarrCommand};
|
|
use readarr::{ReadarrCliHandler, ReadarrCommand};
|
|
use sonarr::{SonarrCliHandler, SonarrCommand};
|
|
use tokio::sync::Mutex;
|
|
|
|
use crate::{app::App, network::NetworkTrait};
|
|
|
|
pub mod lidarr;
|
|
pub mod radarr;
|
|
pub mod readarr;
|
|
pub mod sonarr;
|
|
|
|
#[cfg(test)]
|
|
#[path = "cli_tests.rs"]
|
|
mod cli_tests;
|
|
|
|
#[derive(Debug, Clone, Subcommand, PartialEq, Eq)]
|
|
pub enum Command {
|
|
#[command(subcommand, about = "Commands for manging your Radarr instance")]
|
|
Radarr(RadarrCommand),
|
|
|
|
#[command(subcommand, about = "Commands for manging your Sonarr instance")]
|
|
Sonarr(SonarrCommand),
|
|
|
|
#[command(subcommand, about = "Commands for manging your Lidarr instance")]
|
|
Lidarr(LidarrCommand),
|
|
|
|
#[command(subcommand, about = "Commands for managing your Readarr instance")]
|
|
Readarr(ReadarrCommand),
|
|
|
|
#[command(
|
|
arg_required_else_help = true,
|
|
about = "Generate shell completions for the Managarr CLI"
|
|
)]
|
|
Completions {
|
|
#[arg(value_enum)]
|
|
shell: Shell,
|
|
},
|
|
|
|
#[command(about = "Tail Managarr logs")]
|
|
TailLogs {
|
|
#[arg(long, help = "Disable colored log output")]
|
|
no_color: bool,
|
|
},
|
|
|
|
#[command(about = indoc!{"
|
|
Print the full path to the default configuration file.
|
|
This file can be changed to another location using the '--config-file' flag
|
|
"})]
|
|
ConfigPath,
|
|
}
|
|
|
|
pub trait CliCommandHandler<'a, 'b, T: Into<Command>> {
|
|
fn with(app: &'a Arc<Mutex<App<'b>>>, command: T, network: &'a mut dyn NetworkTrait) -> Self;
|
|
async fn handle(self) -> Result<String>;
|
|
}
|
|
|
|
pub(crate) async fn handle_command(
|
|
app: &Arc<Mutex<App<'_>>>,
|
|
command: Command,
|
|
network: &mut dyn NetworkTrait,
|
|
) -> Result<String> {
|
|
let result = match command {
|
|
Command::Radarr(radarr_command) => {
|
|
RadarrCliHandler::with(app, radarr_command, network)
|
|
.handle()
|
|
.await?
|
|
}
|
|
Command::Sonarr(sonarr_command) => {
|
|
SonarrCliHandler::with(app, sonarr_command, network)
|
|
.handle()
|
|
.await?
|
|
}
|
|
Command::Lidarr(lidarr_command) => {
|
|
LidarrCliHandler::with(app, lidarr_command, network)
|
|
.handle()
|
|
.await?
|
|
}
|
|
Command::Readarr(readarr_command) => {
|
|
ReadarrCliHandler::with(app, readarr_command, network)
|
|
.handle()
|
|
.await?
|
|
}
|
|
_ => String::new(),
|
|
};
|
|
|
|
Ok(result)
|
|
}
|
|
|
|
#[inline]
|
|
pub fn mutex_flags_or_option(positive: bool, negative: bool) -> Option<bool> {
|
|
if positive {
|
|
Some(true)
|
|
} else if negative {
|
|
Some(false)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
pub fn mutex_flags_or_default(positive: bool, negative: bool, default_value: bool) -> bool {
|
|
if positive {
|
|
true
|
|
} else if negative {
|
|
false
|
|
} else {
|
|
default_value
|
|
}
|
|
}
|