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

This commit is contained in:
Dark-Alex-17 committed 2026-08-20 22:47:41 -06:00
1 parent 29186ea03c
commit b9fa3b36c0
5 files changed
+268 -1

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
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 = "add_command_handler_tests.rs"]
mod add_command_handler_tests;
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum ReadarrAddCommand {
#[command(about = "Add new tag")]
Tag {
#[arg(long, help = "The name of the tag to be added", required = true)]
name: String,
},
}
impl From<ReadarrAddCommand> for Command {
fn from(value: ReadarrAddCommand) -> Self {
Command::Readarr(ReadarrCommand::Add(value))
}
}
pub(super) struct ReadarrAddCommandHandler<'a, 'b> {
_app: &'a Arc<Mutex<App<'b>>>,
command: ReadarrAddCommand,
network: &'a mut dyn NetworkTrait,
}
impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrAddCommand> for ReadarrAddCommandHandler<'a, 'b> {
fn with(
app: &'a Arc<Mutex<App<'b>>>,
command: ReadarrAddCommand,
network: &'a mut dyn NetworkTrait,
) -> Self {
ReadarrAddCommandHandler {
_app: app,
command,
network,
}
}
async fn handle(self) -> Result<String> {
let result = match self.command {
ReadarrAddCommand::Tag { name } => {
let resp = self
.network
.handle_network_event(ReadarrEvent::AddTag(name).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
};
Ok(result)
}
}