feat: Added initial Sonarr CLI support and the initial network handler setup for the TUI

This commit is contained in:
2024-11-10 21:23:55 -07:00
parent b6f5b9d08c
commit 60d61b9e31
28 changed files with 2419 additions and 761 deletions
+60
View File
@@ -0,0 +1,60 @@
use std::sync::Arc;
use anyhow::Result;
use clap::Subcommand;
use tokio::sync::Mutex;
use crate::{
app::App,
cli::{CliCommandHandler, Command},
execute_network_event,
network::{sonarr_network::SonarrEvent, NetworkTrait},
};
use super::SonarrCommand;
#[cfg(test)]
#[path = "list_command_handler_tests.rs"]
mod list_command_handler_tests;
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum SonarrListCommand {
#[command(about = "List all series in your Sonarr library")]
Series,
}
impl From<SonarrListCommand> for Command {
fn from(value: SonarrListCommand) -> Self {
Command::Sonarr(SonarrCommand::List(value))
}
}
pub(super) struct SonarrListCommandHandler<'a, 'b> {
app: &'a Arc<Mutex<App<'b>>>,
command: SonarrListCommand,
network: &'a mut dyn NetworkTrait,
}
impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrListCommand> for SonarrListCommandHandler<'a, 'b> {
fn with(
app: &'a Arc<Mutex<App<'b>>>,
command: SonarrListCommand,
network: &'a mut dyn NetworkTrait,
) -> Self {
SonarrListCommandHandler {
app,
command,
network,
}
}
async fn handle(self) -> Result<()> {
match self.command {
SonarrListCommand::Series => {
execute_network_event!(self, SonarrEvent::ListSeries);
}
}
Ok(())
}
}