use std::sync::Arc; use anyhow::Result; use clap::Subcommand; use list_command_handler::{LidarrListCommand, LidarrListCommandHandler}; use tokio::sync::Mutex; use crate::{ app::App, network::NetworkTrait, }; use super::{CliCommandHandler, Command}; mod list_command_handler; #[derive(Debug, Clone, PartialEq, Eq, Subcommand)] pub enum LidarrCommand { #[command( subcommand, about = "Commands to list attributes from your Lidarr instance" )] List(LidarrListCommand), } impl From for Command { fn from(lidarr_command: LidarrCommand) -> Command { Command::Lidarr(lidarr_command) } } pub(super) struct LidarrCliHandler<'a, 'b> { app: &'a Arc>>, command: LidarrCommand, network: &'a mut dyn NetworkTrait, } impl<'a, 'b> CliCommandHandler<'a, 'b, LidarrCommand> for LidarrCliHandler<'a, 'b> { fn with( app: &'a Arc>>, command: LidarrCommand, network: &'a mut dyn NetworkTrait, ) -> Self { LidarrCliHandler { app, command, network, } } async fn handle(self) -> Result { let result = match self.command { LidarrCommand::List(list_command) => { LidarrListCommandHandler::with(self.app, list_command, self.network) .handle() .await? } }; Ok(result) } }