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 = "get_command_handler_tests.rs"]
mod get_command_handler_tests;
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum SonarrGetCommand {
#[command(about = "Get the system status")]
SystemStatus,
}
impl From<SonarrGetCommand> for Command {
fn from(value: SonarrGetCommand) -> Self {
Command::Sonarr(SonarrCommand::Get(value))
}
}
pub(super) struct SonarrGetCommandHandler<'a, 'b> {
_app: &'a Arc<Mutex<App<'b>>>,
command: SonarrGetCommand,
network: &'a mut dyn NetworkTrait,
}
impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrGetCommand> for SonarrGetCommandHandler<'a, 'b> {
fn with(
_app: &'a Arc<Mutex<App<'b>>>,
command: SonarrGetCommand,
network: &'a mut dyn NetworkTrait,
) -> Self {
SonarrGetCommandHandler {
_app,
command,
network,
}
}
async fn handle(self) -> Result<()> {
match self.command {
SonarrGetCommand::SystemStatus => {
execute_network_event!(self, SonarrEvent::GetStatus);
}
}
Ok(())
}
}