feat(radarr): New `--list-custom-formats` option

Used to build a flat list of CFs from the guide.
pull/92/head
Robert Dailey 2 years ago
parent 9eebc227c5
commit 2ba2bf299c

@ -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

@ -2,4 +2,5 @@ namespace Recyclarr.Command;
public interface IRadarrCommand : IServiceCommand
{
bool ListCustomFormats { get; }
}

@ -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; }
}

@ -13,6 +13,7 @@ public class RadarrService : ServiceBase<IRadarrCommand>
{
private readonly IConfigurationLoader<RadarrConfiguration> _configLoader;
private readonly Func<ICustomFormatUpdater> _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<IRadarrCommand>
IConfigurationLoader<RadarrConfiguration> configLoader,
Func<IRadarrQualityDefinitionUpdater> qualityUpdaterFactory,
Func<ICustomFormatUpdater> customFormatUpdaterFactory,
ICustomFormatLister lister,
IFileSystem fs,
IAppPaths paths)
{
@ -30,6 +32,7 @@ public class RadarrService : ServiceBase<IRadarrCommand>
_configLoader = configLoader;
_qualityUpdaterFactory = qualityUpdaterFactory;
_customFormatUpdaterFactory = customFormatUpdaterFactory;
_lister = lister;
_fs = fs;
_paths = paths;
}
@ -38,6 +41,12 @@ public class RadarrService : ServiceBase<IRadarrCommand>
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));

@ -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}));
}
}

@ -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.");
}
}

@ -0,0 +1,6 @@
namespace TrashLib.Radarr.CustomFormat;
public interface ICustomFormatLister
{
void ListCustomFormats();
}

@ -34,6 +34,7 @@ public class RadarrAutofacModule : Module
builder.RegisterType<CustomFormatUpdater>().As<ICustomFormatUpdater>();
builder.RegisterType<LocalRepoCustomFormatJsonParser>().As<IRadarrGuideService>();
builder.RegisterType<CachePersister>().As<ICachePersister>();
builder.RegisterType<CustomFormatLister>().As<ICustomFormatLister>();
// Guide Processor

Loading…
Cancel
Save