From 3f5960c4147afa57a0522a4da3263339764ea559 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Mon, 21 Aug 2023 08:48:11 -0500 Subject: [PATCH] feat: Add score sets and raw output to list custom-formats --- CHANGELOG.md | 4 ++ .../Commands/ListCustomFormatsCommand.cs | 13 ++++- .../Settings/IListCustomFormatSettings.cs | 10 ++++ .../Console/Settings/ISyncSettings.cs | 1 - .../Guide/CustomFormatDataLister.cs | 53 +++++++++++++++++-- .../Guide/CustomFormatDataListerTest.cs | 5 +- 6 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 src/Recyclarr.Cli/Console/Settings/IListCustomFormatSettings.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index de8f16bc..0dc8834d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New `score_set` property available to each profile defined under the top-level `quality_profiles` list. This allows different kinds of pre-defined scores to be chosen from the guide, without having to explicitly override scores in your YAML. +- New `--score-sets` option added to `list custom-formats` which lists all score sets that CFs are a + member of, instead of the CFs themselves. +- New `--raw` option added to `list custom-formats` which omits boilerplate output and formatting. + Useful for scripting. ### Changed diff --git a/src/Recyclarr.Cli/Console/Commands/ListCustomFormatsCommand.cs b/src/Recyclarr.Cli/Console/Commands/ListCustomFormatsCommand.cs index b03c13ac..7e9a531e 100644 --- a/src/Recyclarr.Cli/Console/Commands/ListCustomFormatsCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/ListCustomFormatsCommand.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using JetBrains.Annotations; using Recyclarr.Cli.Console.Helpers; +using Recyclarr.Cli.Console.Settings; using Recyclarr.Cli.Pipelines.CustomFormat.Guide; using Recyclarr.TrashLib.Config; using Recyclarr.TrashLib.Repo; @@ -20,12 +21,20 @@ internal class ListCustomFormatsCommand : AsyncCommand")] [EnumDescription("The service type to obtain information about.")] [UsedImplicitly(ImplicitUseKindFlags.Assign)] public SupportedServices Service { get; init; } + + [CommandOption("--score-sets")] + [Description("Instead of listing custom formats, list the score sets all custom formats are part of.")] + public bool ScoreSets { get; init; } = false; + + [CommandOption("--raw")] + [Description("Omit any boilerplate text or colored formatting. This option primarily exists for scripts.")] + public bool Raw { get; init; } = false; } public ListCustomFormatsCommand(CustomFormatDataLister lister, ITrashGuidesRepo repo) @@ -37,7 +46,7 @@ internal class ListCustomFormatsCommand : AsyncCommand ExecuteAsync(CommandContext context, CliSettings settings) { await _repo.Update(); - _lister.ListCustomFormats(settings.Service); + _lister.List(settings); return 0; } } diff --git a/src/Recyclarr.Cli/Console/Settings/IListCustomFormatSettings.cs b/src/Recyclarr.Cli/Console/Settings/IListCustomFormatSettings.cs new file mode 100644 index 00000000..eff1612a --- /dev/null +++ b/src/Recyclarr.Cli/Console/Settings/IListCustomFormatSettings.cs @@ -0,0 +1,10 @@ +using Recyclarr.TrashLib.Config; + +namespace Recyclarr.Cli.Console.Settings; + +public interface IListCustomFormatSettings +{ + SupportedServices Service { get; } + bool ScoreSets { get; } + bool Raw { get; } +} diff --git a/src/Recyclarr.Cli/Console/Settings/ISyncSettings.cs b/src/Recyclarr.Cli/Console/Settings/ISyncSettings.cs index c2fbe434..fc37a82f 100644 --- a/src/Recyclarr.Cli/Console/Settings/ISyncSettings.cs +++ b/src/Recyclarr.Cli/Console/Settings/ISyncSettings.cs @@ -5,7 +5,6 @@ namespace Recyclarr.Cli.Console.Settings; public interface ISyncSettings { SupportedServices? Service { get; } - // ReSharper disable once ReturnTypeCanBeEnumerable.Global IReadOnlyCollection Configs { get; } bool Preview { get; } IReadOnlyCollection? Instances { get; } diff --git a/src/Recyclarr.Cli/Pipelines/CustomFormat/Guide/CustomFormatDataLister.cs b/src/Recyclarr.Cli/Pipelines/CustomFormat/Guide/CustomFormatDataLister.cs index 0ed413da..534f5044 100644 --- a/src/Recyclarr.Cli/Pipelines/CustomFormat/Guide/CustomFormatDataLister.cs +++ b/src/Recyclarr.Cli/Pipelines/CustomFormat/Guide/CustomFormatDataLister.cs @@ -1,3 +1,4 @@ +using Recyclarr.Cli.Console.Settings; using Recyclarr.TrashLib.Config; using Spectre.Console; @@ -14,9 +15,48 @@ public class CustomFormatDataLister _guide = guide; } - public void ListCustomFormats(SupportedServices serviceType) + public void List(IListCustomFormatSettings settings) { - _console.WriteLine("\nList of Custom Formats in the TRaSH Guides:"); + switch (settings) + { + case {ScoreSets: true}: + ListScoreSets(settings.Service, settings.Raw); + break; + + default: + ListCustomFormats(settings.Service, settings.Raw); + break; + } + } + + private void ListScoreSets(SupportedServices serviceType, bool raw) + { + if (!raw) + { + _console.WriteLine( + "\nThe following score sets are available. Use these with the `score_set` property in any " + + "quality profile defined under the top-level `quality_profiles` list."); + + _console.WriteLine(); + } + + var scoreSets = _guide.GetCustomFormatData(serviceType) + .SelectMany(x => x.TrashScores.Keys) + .Distinct(StringComparer.InvariantCultureIgnoreCase) + .Order(StringComparer.InvariantCultureIgnoreCase); + + foreach (var set in scoreSets) + { + _console.WriteLine(raw ? set : $" - {set}"); + } + } + + private void ListCustomFormats(SupportedServices serviceType, bool raw) + { + if (!raw) + { + _console.WriteLine("\nList of Custom Formats in the TRaSH Guides:"); + } var categories = _guide.GetCustomFormatData(serviceType) .OrderBy(x => x.Name) @@ -34,8 +74,11 @@ public class CustomFormatDataLister } } - _console.WriteLine( - "\nThe above Custom Formats are in YAML format and ready to be copied & pasted " + - "under the `trash_ids:` property."); + if (!raw) + { + _console.WriteLine( + "\nThe above Custom Formats are in YAML format and ready to be copied & pasted " + + "under the `trash_ids:` property."); + } } } diff --git a/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Guide/CustomFormatDataListerTest.cs b/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Guide/CustomFormatDataListerTest.cs index 66b6ad03..6f1e39ca 100644 --- a/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Guide/CustomFormatDataListerTest.cs +++ b/src/tests/Recyclarr.Cli.Tests/Pipelines/CustomFormat/Guide/CustomFormatDataListerTest.cs @@ -1,3 +1,4 @@ +using Recyclarr.Cli.Console.Settings; using Recyclarr.Cli.Pipelines.CustomFormat.Guide; using Recyclarr.TrashLib.TestLibrary; using Spectre.Console.Testing; @@ -12,6 +13,7 @@ public class CustomFormatDataListerTest public void Custom_formats_appear_in_console_output( [Frozen(Matching.ImplementedInterfaces)] TestConsole console, [Frozen] ICustomFormatGuideService guide, + IListCustomFormatSettings settings, CustomFormatDataLister sut) { var testData = new[] @@ -21,8 +23,9 @@ public class CustomFormatDataListerTest }; guide.GetCustomFormatData(default!).ReturnsForAnyArgs(testData); + settings.ScoreSets.Returns(false); - sut.ListCustomFormats(default!); + sut.List(settings); console.Output.Should().ContainAll( testData.SelectMany(x => new[] {x.Name, x.TrashId}));