feat(readarr): fetch Readarr author details and expose them on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-26 14:35:46 -06:00
1 parent 817fe4d135
commit 5042dbdb3a
6 files changed
+158 -2

No files matched your search

+16
View File
@@ -18,6 +18,15 @@ mod get_command_handler_tests;
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
pub enum ReadarrGetCommand {
#[command(about = "Get detailed information for the author with the given ID")]
AuthorDetails {
#[arg(
long,
help = "The Readarr ID of the author whose details you wish to fetch",
required = true
)]
author_id: i64,
},
#[command(about = "Fetch the host config for your Readarr instance")]
HostConfig,
#[command(about = "Fetch the security config for your Readarr instance")]
@@ -53,6 +62,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrGetCommand> for ReadarrGetCommandH
async fn handle(self) -> Result<String> {
let result = match self.command {
ReadarrGetCommand::AuthorDetails { author_id } => {
let resp = self
.network
.handle_network_event(ReadarrEvent::GetAuthorDetails(author_id).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrGetCommand::HostConfig => {
let resp = self
.network
+56 -1
View File
@@ -18,9 +18,38 @@ mod tests {
}
mod cli {
use super::*;
use clap::error::ErrorKind;
use pretty_assertions::assert_eq;
use rstest::rstest;
use super::*;
#[test]
fn test_author_details_requires_author_id() {
let result =
Cli::command().try_get_matches_from(["managarr", "readarr", "get", "author-details"]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_author_details_requirements_satisfied() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"get",
"author-details",
"--author-id",
"1",
]);
assert_ok!(&result);
}
#[rstest]
fn test_get_commands_have_no_arg_requirements(
#[values("host-config", "security-config", "system-status")] subcommand: &str,
@@ -48,6 +77,32 @@ mod tests {
network::{MockNetworkTrait, NetworkEvent, readarr_network::ReadarrEvent},
};
#[tokio::test]
async fn test_handle_get_author_details_command() {
let expected_author_id = 1;
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::GetAuthorDetails(expected_author_id).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::test_default()));
let get_author_details_command = ReadarrGetCommand::AuthorDetails { author_id: 1 };
let result =
ReadarrGetCommandHandler::with(&app_arc, get_author_details_command, &mut mock_network)
.handle()
.await;
assert_ok!(&result);
}
#[tokio::test]
async fn test_handle_get_host_config_command() {
let mut mock_network = MockNetworkTrait::new();