feat(cli): Support for adding a series to Sonarr

This commit is contained in:
2024-11-24 14:38:23 -07:00
parent 8125bd5ae0
commit 53a59cdb4c
2 changed files with 55 additions and 2 deletions
+4 -1
View File
@@ -27,6 +27,8 @@ pub enum SonarrAddCommand {
required = true required = true
)] )]
tvdb_id: i64, tvdb_id: i64,
#[arg(long, help = "The title of the series", required = true)]
title: String,
#[arg( #[arg(
long, long,
help = "The root folder path where all series data and metadata should live", help = "The root folder path where all series data and metadata should live",
@@ -117,6 +119,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrAddCommand> for SonarrAddCommandHan
let result = match self.command { let result = match self.command {
SonarrAddCommand::Series { SonarrAddCommand::Series {
tvdb_id, tvdb_id,
title,
root_folder_path, root_folder_path,
quality_profile_id, quality_profile_id,
language_profile_id, language_profile_id,
@@ -129,7 +132,7 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrAddCommand> for SonarrAddCommandHan
} => { } => {
let body = AddSeriesBody { let body = AddSeriesBody {
tvdb_id, tvdb_id,
title: String::new(), title,
monitored: !disable_monitoring, monitored: !disable_monitoring,
root_folder_path, root_folder_path,
quality_profile_id, quality_profile_id,
+51 -1
View File
@@ -87,6 +87,32 @@ mod tests {
"1", "1",
"--language-profile-id", "--language-profile-id",
"1", "1",
"--title",
"test",
]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_add_series_requires_title() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"add",
"series",
"--tvdb-id",
"1",
"--root-folder-path",
"test",
"--quality-profile-id",
"1",
"--language-profile-id",
"1",
]); ]);
assert!(result.is_err()); assert!(result.is_err());
@@ -109,6 +135,8 @@ mod tests {
"1", "1",
"--language-profile-id", "--language-profile-id",
"1", "1",
"--title",
"test",
]); ]);
assert!(result.is_err()); assert!(result.is_err());
@@ -131,6 +159,8 @@ mod tests {
"test", "test",
"--language-profile-id", "--language-profile-id",
"1", "1",
"--title",
"test",
]); ]);
assert!(result.is_err()); assert!(result.is_err());
@@ -153,6 +183,8 @@ mod tests {
"test", "test",
"--quality-profile-id", "--quality-profile-id",
"1", "1",
"--title",
"test",
]); ]);
assert!(result.is_err()); assert!(result.is_err());
@@ -173,6 +205,8 @@ mod tests {
"series", "series",
"--tvdb-id", "--tvdb-id",
"1", "1",
"--title",
"test",
"--root-folder-path", "--root-folder-path",
"/test", "/test",
"--quality-profile-id", "--quality-profile-id",
@@ -193,6 +227,8 @@ mod tests {
"sonarr", "sonarr",
"add", "add",
"series", "series",
"--title",
"test",
"--root-folder-path", "--root-folder-path",
"/test", "/test",
"--quality-profile-id", "--quality-profile-id",
@@ -221,6 +257,8 @@ mod tests {
"1", "1",
"--tvdb-id", "--tvdb-id",
"1", "1",
"--title",
"test",
"--series-type", "--series-type",
"test", "test",
]); ]);
@@ -243,6 +281,8 @@ mod tests {
"--language-profile-id", "--language-profile-id",
"1", "1",
"--tvdb-id", "--tvdb-id",
"--title",
"test",
"1", "1",
"--monitor", "--monitor",
"test", "test",
@@ -256,6 +296,7 @@ mod tests {
fn test_add_series_defaults() { fn test_add_series_defaults() {
let expected_args = SonarrAddCommand::Series { let expected_args = SonarrAddCommand::Series {
tvdb_id: 1, tvdb_id: 1,
title: "test".to_owned(),
root_folder_path: "/test".to_owned(), root_folder_path: "/test".to_owned(),
quality_profile_id: 1, quality_profile_id: 1,
language_profile_id: 1, language_profile_id: 1,
@@ -278,6 +319,8 @@ mod tests {
"1", "1",
"--language-profile-id", "--language-profile-id",
"1", "1",
"--title",
"test",
"--tvdb-id", "--tvdb-id",
"1", "1",
]); ]);
@@ -292,6 +335,7 @@ mod tests {
fn test_add_series_tags_is_repeatable() { fn test_add_series_tags_is_repeatable() {
let expected_args = SonarrAddCommand::Series { let expected_args = SonarrAddCommand::Series {
tvdb_id: 1, tvdb_id: 1,
title: "test".to_owned(),
root_folder_path: "/test".to_owned(), root_folder_path: "/test".to_owned(),
quality_profile_id: 1, quality_profile_id: 1,
language_profile_id: 1, language_profile_id: 1,
@@ -316,6 +360,8 @@ mod tests {
"1", "1",
"--tvdb-id", "--tvdb-id",
"1", "1",
"--title",
"test",
"--tag", "--tag",
"1", "1",
"--tag", "--tag",
@@ -332,6 +378,7 @@ mod tests {
fn test_add_series_all_args_defined() { fn test_add_series_all_args_defined() {
let expected_args = SonarrAddCommand::Series { let expected_args = SonarrAddCommand::Series {
tvdb_id: 1, tvdb_id: 1,
title: "test".to_owned(),
root_folder_path: "/test".to_owned(), root_folder_path: "/test".to_owned(),
quality_profile_id: 1, quality_profile_id: 1,
language_profile_id: 1, language_profile_id: 1,
@@ -360,6 +407,8 @@ mod tests {
"--disable-season-folders", "--disable-season-folders",
"--tvdb-id", "--tvdb-id",
"1", "1",
"--title",
"test",
"--tag", "--tag",
"1", "1",
"--tag", "--tag",
@@ -455,7 +504,7 @@ mod tests {
async fn test_handle_add_series_command() { async fn test_handle_add_series_command() {
let expected_add_series_body = AddSeriesBody { let expected_add_series_body = AddSeriesBody {
tvdb_id: 1, tvdb_id: 1,
title: String::new(), title: "test".to_owned(),
root_folder_path: "/test".to_owned(), root_folder_path: "/test".to_owned(),
quality_profile_id: 1, quality_profile_id: 1,
language_profile_id: 1, language_profile_id: 1,
@@ -484,6 +533,7 @@ mod tests {
let app_arc = Arc::new(Mutex::new(App::default())); let app_arc = Arc::new(Mutex::new(App::default()));
let add_series_command = SonarrAddCommand::Series { let add_series_command = SonarrAddCommand::Series {
tvdb_id: 1, tvdb_id: 1,
title: "test".to_owned(),
root_folder_path: "/test".to_owned(), root_folder_path: "/test".to_owned(),
quality_profile_id: 1, quality_profile_id: 1,
language_profile_id: 1, language_profile_id: 1,