feat(readarr): manually download a release and expose the command on the CLI

This commit is contained in:
Dark-Alex-17 committed 2026-08-28 14:22:57 -06:00
1 parent 999a22a37f
commit 5a730f2f05
6 files changed
+251 -3

No files matched your search

+20
View File
@@ -16,6 +16,7 @@ use trigger_automatic_search_command_handler::{
use super::{CliCommandHandler, Command};
use crate::models::readarr_models::ReadarrTaskName;
use crate::models::servarr_models::ReleaseDownloadBody;
use crate::network::readarr_network::ReadarrEvent;
use crate::{app::App, network::NetworkTrait};
@@ -68,6 +69,17 @@ pub enum ReadarrCommand {
about = "Commands to trigger automatic searches for releases of different resources in your Readarr instance"
)]
TriggerAutomaticSearch(ReadarrTriggerAutomaticSearchCommand),
#[command(about = "Manually download the given release")]
DownloadRelease {
#[arg(long, help = "The GUID of the release to download", required = true)]
guid: String,
#[arg(
long,
help = "The indexer ID to download the release from",
required = true
)]
indexer_id: i64,
},
#[command(about = "Mark the Readarr history item with the given ID as 'failed'")]
MarkHistoryItemAsFailed {
#[arg(
@@ -184,6 +196,14 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrCommand> for ReadarrCliHandler<'a,
.handle()
.await?
}
ReadarrCommand::DownloadRelease { guid, indexer_id } => {
let params = ReleaseDownloadBody { guid, indexer_id };
let resp = self
.network
.handle_network_event(ReadarrEvent::DownloadRelease(params).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
ReadarrCommand::MarkHistoryItemAsFailed { history_item_id } => {
let _ = self
.network
+81
View File
@@ -26,6 +26,55 @@ mod tests {
);
}
#[test]
fn test_download_release_requires_guid() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"download-release",
"--indexer-id",
"6",
]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_download_release_requires_indexer_id() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"download-release",
"--guid",
"test-release-guid",
]);
assert_err!(&result);
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_download_release_requirements_satisfied() {
let result = Cli::command().try_get_matches_from([
"managarr",
"readarr",
"download-release",
"--guid",
"test-release-guid",
"--indexer-id",
"6",
]);
assert_ok!(&result);
}
#[test]
fn test_mark_history_item_as_failed_requirements_satisfied() {
let result = Cli::command().try_get_matches_from([
@@ -161,6 +210,7 @@ mod tests {
use tokio::sync::Mutex;
use crate::models::readarr_models::{ReadarrSerdeable, ReadarrTaskName};
use crate::models::servarr_models::ReleaseDownloadBody;
use crate::{
app::App,
cli::{
@@ -202,6 +252,37 @@ mod tests {
assert_ok!(&result);
}
#[tokio::test]
async fn test_download_release_command() {
let expected_release_download_body = ReleaseDownloadBody {
guid: "test-release-guid".to_owned(),
indexer_id: 6,
};
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
ReadarrEvent::DownloadRelease(expected_release_download_body).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Readarr(ReadarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::test_default()));
let download_release_command = ReadarrCommand::DownloadRelease {
guid: "test-release-guid".to_owned(),
indexer_id: 6,
};
let result = ReadarrCliHandler::with(&app_arc, download_release_command, &mut mock_network)
.handle()
.await;
assert_ok!(&result);
}
#[tokio::test]
async fn test_search_new_author_command() {
let expected_query = "test author".to_owned();