feat(readarr): delete Readarr tags and expose the command on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-26 10:21:55 -06:00
1 parent b9fa3b36c0
commit e8e3376327
5 files changed
+251 -1

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
use std::sync::Arc;
use anyhow::Result;
use clap::Subcommand;
use tokio::sync::Mutex;
use super::ReadarrCommand;
use crate::{
app::App,
cli::{CliCommandHandler, Command},
network::{NetworkTrait, readarr_network::ReadarrEvent},
};
#[cfg(test)]
#[path = "delete_command_handler_tests.rs"]
mod delete_command_handler_tests;
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum ReadarrDeleteCommand {
#[command(about = "Delete the tag with the specified ID")]
Tag {
#[arg(long, help = "The ID of the tag to delete", required = true)]
tag_id: i64,
},
}
impl From<ReadarrDeleteCommand> for Command {
fn from(value: ReadarrDeleteCommand) -> Self {
Command::Readarr(ReadarrCommand::Delete(value))
}
}
pub(super) struct ReadarrDeleteCommandHandler<'a, 'b> {
_app: &'a Arc<Mutex<App<'b>>>,
command: ReadarrDeleteCommand,
network: &'a mut dyn NetworkTrait,
}
impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrDeleteCommand>
for ReadarrDeleteCommandHandler<'a, 'b>
{
fn with(
app: &'a Arc<Mutex<App<'b>>>,
command: ReadarrDeleteCommand,
network: &'a mut dyn NetworkTrait,
) -> Self {
ReadarrDeleteCommandHandler {
_app: app,
command,
network,
}
}
async fn handle(self) -> Result<String> {
let result = match self.command {
ReadarrDeleteCommand::Tag { tag_id } => {
let resp = self
.network
.handle_network_event(ReadarrEvent::DeleteTag(tag_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
};
Ok(result)
}
}