From 2ba2bf299cbfe9b1c57759815d0f73c68eb45fb7 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 17 Jun 2022 15:25:46 -0500 Subject: [PATCH] feat(radarr): New `--list-custom-formats` option Used to build a flat list of CFs from the guide. --- CHANGELOG.md | 5 +++ src/Recyclarr/Command/IRadarrCommand.cs | 1 + src/Recyclarr/Command/RadarrCommand.cs | 4 +++ .../Command/Services/RadarrService.cs | 9 +++++ .../CustomFormat/CustomFormatListerTest.cs | 36 +++++++++++++++++++ .../Radarr/CustomFormat/CustomFormatLister.cs | 33 +++++++++++++++++ .../CustomFormat/ICustomFormatLister.cs | 6 ++++ src/TrashLib/Radarr/RadarrAutofacModule.cs | 1 + 8 files changed, 95 insertions(+) create mode 100644 src/TrashLib.Tests/Radarr/CustomFormat/CustomFormatListerTest.cs create mode 100644 src/TrashLib/Radarr/CustomFormat/CustomFormatLister.cs create mode 100644 src/TrashLib/Radarr/CustomFormat/ICustomFormatLister.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index b2327e83..2c35fc93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Radarr: New `--list-custom-formats` CLI option for getting a flat list of all CFs in the guide in + YAML format, ready to copy & paste. + ## [2.2.1] - 2022-06-18 ### Changed diff --git a/src/Recyclarr/Command/IRadarrCommand.cs b/src/Recyclarr/Command/IRadarrCommand.cs index 7748d04d..81cfb493 100644 --- a/src/Recyclarr/Command/IRadarrCommand.cs +++ b/src/Recyclarr/Command/IRadarrCommand.cs @@ -2,4 +2,5 @@ namespace Recyclarr.Command; public interface IRadarrCommand : IServiceCommand { + bool ListCustomFormats { get; } } diff --git a/src/Recyclarr/Command/RadarrCommand.cs b/src/Recyclarr/Command/RadarrCommand.cs index 56612b7c..5a1e8d1d 100644 --- a/src/Recyclarr/Command/RadarrCommand.cs +++ b/src/Recyclarr/Command/RadarrCommand.cs @@ -32,4 +32,8 @@ internal class RadarrCommand : ServiceCommand, IRadarrCommand { await _service.Value.Execute(this); } + + [CommandOption("list-custom-formats", Description = + "List available custom formats from the guide in YAML format.")] + public bool ListCustomFormats { get; [UsedImplicitly] set; } } diff --git a/src/Recyclarr/Command/Services/RadarrService.cs b/src/Recyclarr/Command/Services/RadarrService.cs index b45561e2..d4d8bff4 100644 --- a/src/Recyclarr/Command/Services/RadarrService.cs +++ b/src/Recyclarr/Command/Services/RadarrService.cs @@ -13,6 +13,7 @@ public class RadarrService : ServiceBase { private readonly IConfigurationLoader _configLoader; private readonly Func _customFormatUpdaterFactory; + private readonly ICustomFormatLister _lister; private readonly IFileSystem _fs; private readonly IAppPaths _paths; private readonly ILogger _log; @@ -23,6 +24,7 @@ public class RadarrService : ServiceBase IConfigurationLoader configLoader, Func qualityUpdaterFactory, Func customFormatUpdaterFactory, + ICustomFormatLister lister, IFileSystem fs, IAppPaths paths) { @@ -30,6 +32,7 @@ public class RadarrService : ServiceBase _configLoader = configLoader; _qualityUpdaterFactory = qualityUpdaterFactory; _customFormatUpdaterFactory = customFormatUpdaterFactory; + _lister = lister; _fs = fs; _paths = paths; } @@ -38,6 +41,12 @@ public class RadarrService : ServiceBase protected override async Task Process(IRadarrCommand cmd) { + if (cmd.ListCustomFormats) + { + _lister.ListCustomFormats(); + return; + } + foreach (var config in _configLoader.LoadMany(cmd.Config, "radarr")) { _log.Information("Processing server {Url}", FlurlLogging.SanitizeUrl(config.BaseUrl)); diff --git a/src/TrashLib.Tests/Radarr/CustomFormat/CustomFormatListerTest.cs b/src/TrashLib.Tests/Radarr/CustomFormat/CustomFormatListerTest.cs new file mode 100644 index 00000000..009d9336 --- /dev/null +++ b/src/TrashLib.Tests/Radarr/CustomFormat/CustomFormatListerTest.cs @@ -0,0 +1,36 @@ +using AutoFixture.NUnit3; +using CliFx.Infrastructure; +using FluentAssertions; +using NSubstitute; +using NUnit.Framework; +using TestLibrary.AutoFixture; +using TrashLib.Radarr.CustomFormat; +using TrashLib.Radarr.CustomFormat.Guide; +using TrashLib.TestLibrary; + +namespace TrashLib.Tests.Radarr.CustomFormat; + +[TestFixture] +[Parallelizable(ParallelScope.All)] +public class CustomFormatListerTest +{ + [Test, AutoMockData] + public void Custom_formats_appear_in_console_output( + [Frozen] IRadarrGuideService guide, + [Frozen(Matching.ImplementedInterfaces)] FakeInMemoryConsole console, + CustomFormatLister sut) + { + var testData = new[] + { + NewCf.Data("First", "123"), + NewCf.Data("Second", "456") + }; + + guide.GetCustomFormatData().Returns(testData); + + sut.ListCustomFormats(); + + console.ReadOutputString().Should().ContainAll( + testData.SelectMany(x => new[] {x.Name, x.TrashId})); + } +} diff --git a/src/TrashLib/Radarr/CustomFormat/CustomFormatLister.cs b/src/TrashLib/Radarr/CustomFormat/CustomFormatLister.cs new file mode 100644 index 00000000..b468405e --- /dev/null +++ b/src/TrashLib/Radarr/CustomFormat/CustomFormatLister.cs @@ -0,0 +1,33 @@ +using CliFx.Infrastructure; +using JetBrains.Annotations; +using TrashLib.Radarr.CustomFormat.Guide; + +namespace TrashLib.Radarr.CustomFormat; + +[UsedImplicitly] +public class CustomFormatLister : ICustomFormatLister +{ + private readonly IConsole _console; + private readonly IRadarrGuideService _guide; + + public CustomFormatLister(IConsole console, IRadarrGuideService guide) + { + _console = console; + _guide = guide; + } + + public void ListCustomFormats() + { + _console.Output.WriteLine("\nList of Custom Formats in the TRaSH Guides:\n"); + + var profilesFromGuide = _guide.GetCustomFormatData(); + foreach (var profile in profilesFromGuide) + { + _console.Output.WriteLine($" - {profile.TrashId} # {profile.Name}"); + } + + _console.Output.WriteLine( + "\nThe above Custom Formats are in YAML format and ready to be copied & pasted " + + "under the `trash_ids:` property."); + } +} diff --git a/src/TrashLib/Radarr/CustomFormat/ICustomFormatLister.cs b/src/TrashLib/Radarr/CustomFormat/ICustomFormatLister.cs new file mode 100644 index 00000000..241ba373 --- /dev/null +++ b/src/TrashLib/Radarr/CustomFormat/ICustomFormatLister.cs @@ -0,0 +1,6 @@ +namespace TrashLib.Radarr.CustomFormat; + +public interface ICustomFormatLister +{ + void ListCustomFormats(); +} diff --git a/src/TrashLib/Radarr/RadarrAutofacModule.cs b/src/TrashLib/Radarr/RadarrAutofacModule.cs index 8fbbb509..faa69d43 100644 --- a/src/TrashLib/Radarr/RadarrAutofacModule.cs +++ b/src/TrashLib/Radarr/RadarrAutofacModule.cs @@ -34,6 +34,7 @@ public class RadarrAutofacModule : Module builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); // Guide Processor