feat: Add score sets and raw output to list custom-formats

json-serializing-nullable-fields-issue
Robert Dailey 1 year ago
parent 81ab62eca2
commit 3f5960c414

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

@ -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<ListCustomFormatsCommand.
[UsedImplicitly]
[SuppressMessage("Design", "CA1034:Nested types should not be visible")]
public class CliSettings : BaseCommandSettings
public class CliSettings : BaseCommandSettings, IListCustomFormatSettings
{
[CommandArgument(0, "<service_type>")]
[EnumDescription<SupportedServices>("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<ListCustomFormatsCommand.
public override async Task<int> ExecuteAsync(CommandContext context, CliSettings settings)
{
await _repo.Update();
_lister.ListCustomFormats(settings.Service);
_lister.List(settings);
return 0;
}
}

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

@ -5,7 +5,6 @@ namespace Recyclarr.Cli.Console.Settings;
public interface ISyncSettings
{
SupportedServices? Service { get; }
// ReSharper disable once ReturnTypeCanBeEnumerable.Global
IReadOnlyCollection<string> Configs { get; }
bool Preview { get; }
IReadOnlyCollection<string>? Instances { get; }

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

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

Loading…
Cancel
Save