This is in preparation for changes to list template includesjson-serializing-nullable-fields-issue
parent
802a0466c5
commit
175aa6733b
@ -1,60 +0,0 @@
|
|||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Recyclarr.Cli.Console.Helpers;
|
|
||||||
using Recyclarr.Cli.Processors.Config;
|
|
||||||
using Recyclarr.TrashLib.Config.Listers;
|
|
||||||
using Recyclarr.TrashLib.Config.Parsing.ErrorHandling;
|
|
||||||
using Recyclarr.TrashLib.ExceptionTypes;
|
|
||||||
using Recyclarr.TrashLib.Repo;
|
|
||||||
using Spectre.Console.Cli;
|
|
||||||
|
|
||||||
namespace Recyclarr.Cli.Console.Commands;
|
|
||||||
|
|
||||||
[UsedImplicitly]
|
|
||||||
[Description("List configuration files in various ways.")]
|
|
||||||
public class ConfigListCommand : AsyncCommand<ConfigListCommand.CliSettings>
|
|
||||||
{
|
|
||||||
private readonly ILogger _log;
|
|
||||||
private readonly ConfigListProcessor _processor;
|
|
||||||
private readonly IMultiRepoUpdater _repoUpdater;
|
|
||||||
|
|
||||||
[SuppressMessage("Design", "CA1034:Nested types should not be visible")]
|
|
||||||
public class CliSettings : BaseCommandSettings
|
|
||||||
{
|
|
||||||
[CommandArgument(0, "[ListCategory]")]
|
|
||||||
[EnumDescription<ConfigCategory>(
|
|
||||||
"The type of configuration information to list. If not specified, defaults to 'local'.")]
|
|
||||||
public ConfigCategory ListCategory { get; [UsedImplicitly] init; } = ConfigCategory.Local;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigListCommand(ILogger log, ConfigListProcessor processor, IMultiRepoUpdater repoUpdater)
|
|
||||||
{
|
|
||||||
_log = log;
|
|
||||||
_processor = processor;
|
|
||||||
_repoUpdater = repoUpdater;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<int> ExecuteAsync(CommandContext context, CliSettings settings)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await _repoUpdater.UpdateAllRepositories(settings.CancellationToken);
|
|
||||||
_processor.Process(settings.ListCategory);
|
|
||||||
}
|
|
||||||
catch (FileExistsException e)
|
|
||||||
{
|
|
||||||
_log.Error(
|
|
||||||
"The file {ConfigFile} already exists. Please choose another path or " +
|
|
||||||
"delete/move the existing file and run this command again", e.AttemptedPath);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
catch (NoConfigurationFilesException)
|
|
||||||
{
|
|
||||||
_log.Error("No configuration files found");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,46 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Recyclarr.Cli.Processors.Config;
|
||||||
|
using Recyclarr.TrashLib.Config.Parsing.ErrorHandling;
|
||||||
|
using Recyclarr.TrashLib.Repo;
|
||||||
|
using Spectre.Console.Cli;
|
||||||
|
|
||||||
|
namespace Recyclarr.Cli.Console.Commands;
|
||||||
|
|
||||||
|
[UsedImplicitly]
|
||||||
|
[Description("List local configuration files.")]
|
||||||
|
public class ConfigListLocalCommand : AsyncCommand<ConfigListLocalCommand.CliSettings>
|
||||||
|
{
|
||||||
|
private readonly ILogger _log;
|
||||||
|
private readonly ConfigListLocalProcessor _processor;
|
||||||
|
private readonly IMultiRepoUpdater _repoUpdater;
|
||||||
|
|
||||||
|
[SuppressMessage("Design", "CA1034:Nested types should not be visible")]
|
||||||
|
public class CliSettings : BaseCommandSettings
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigListLocalCommand(ILogger log, ConfigListLocalProcessor processor, IMultiRepoUpdater repoUpdater)
|
||||||
|
{
|
||||||
|
_log = log;
|
||||||
|
_processor = processor;
|
||||||
|
_repoUpdater = repoUpdater;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<int> ExecuteAsync(CommandContext context, CliSettings settings)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _repoUpdater.UpdateAllRepositories(settings.CancellationToken);
|
||||||
|
_processor.Process();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (NoConfigurationFilesException)
|
||||||
|
{
|
||||||
|
_log.Error("No configuration files found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Recyclarr.Cli.Processors.Config;
|
||||||
|
using Recyclarr.TrashLib.Config.Parsing.ErrorHandling;
|
||||||
|
using Recyclarr.TrashLib.Repo;
|
||||||
|
using Spectre.Console.Cli;
|
||||||
|
|
||||||
|
namespace Recyclarr.Cli.Console.Commands;
|
||||||
|
|
||||||
|
[UsedImplicitly]
|
||||||
|
[Description("List local configuration files.")]
|
||||||
|
public class ConfigListTemplatesCommand : AsyncCommand<ConfigListTemplatesCommand.CliSettings>
|
||||||
|
{
|
||||||
|
private readonly ILogger _log;
|
||||||
|
private readonly ConfigListTemplateProcessor _processor;
|
||||||
|
private readonly IMultiRepoUpdater _repoUpdater;
|
||||||
|
|
||||||
|
[SuppressMessage("Design", "CA1034:Nested types should not be visible")]
|
||||||
|
public class CliSettings : BaseCommandSettings
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigListTemplatesCommand(ILogger log, ConfigListTemplateProcessor processor, IMultiRepoUpdater repoUpdater)
|
||||||
|
{
|
||||||
|
_log = log;
|
||||||
|
_processor = processor;
|
||||||
|
_repoUpdater = repoUpdater;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<int> ExecuteAsync(CommandContext context, CliSettings settings)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _repoUpdater.UpdateAllRepositories(settings.CancellationToken);
|
||||||
|
_processor.Process();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (NoConfigurationFilesException)
|
||||||
|
{
|
||||||
|
_log.Error("No configuration files found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +0,0 @@
|
|||||||
using Autofac.Features.Indexed;
|
|
||||||
using Recyclarr.TrashLib.Config.Listers;
|
|
||||||
|
|
||||||
namespace Recyclarr.Cli.Processors.Config;
|
|
||||||
|
|
||||||
public class ConfigListProcessor
|
|
||||||
{
|
|
||||||
private readonly ILogger _log;
|
|
||||||
private readonly IIndex<ConfigCategory, IConfigLister> _configListers;
|
|
||||||
|
|
||||||
public ConfigListProcessor(ILogger log, IIndex<ConfigCategory, IConfigLister> configListers)
|
|
||||||
{
|
|
||||||
_log = log;
|
|
||||||
_configListers = configListers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Process(ConfigCategory listCategory)
|
|
||||||
{
|
|
||||||
_log.Debug("Listing configuration for category {Category}", listCategory);
|
|
||||||
if (!_configListers.TryGetValue(listCategory, out var lister))
|
|
||||||
{
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(listCategory), listCategory, "Unknown list category");
|
|
||||||
}
|
|
||||||
|
|
||||||
lister.List();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +1,26 @@
|
|||||||
|
using Recyclarr.TrashLib.Config;
|
||||||
using Recyclarr.TrashLib.Config.Services;
|
using Recyclarr.TrashLib.Config.Services;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
|
||||||
namespace Recyclarr.TrashLib.Config.Listers;
|
namespace Recyclarr.Cli.Processors.Config;
|
||||||
|
|
||||||
public class ConfigTemplateLister : IConfigLister
|
public class ConfigListTemplateProcessor
|
||||||
{
|
{
|
||||||
private readonly IAnsiConsole _console;
|
private readonly IAnsiConsole _console;
|
||||||
private readonly IConfigTemplateGuideService _guideService;
|
private readonly IConfigTemplateGuideService _guideService;
|
||||||
|
|
||||||
public ConfigTemplateLister(
|
public ConfigListTemplateProcessor(IAnsiConsole console, IConfigTemplateGuideService guideService)
|
||||||
IAnsiConsole console,
|
|
||||||
IConfigTemplateGuideService guideService)
|
|
||||||
{
|
{
|
||||||
_console = console;
|
_console = console;
|
||||||
_guideService = guideService;
|
_guideService = guideService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void List()
|
public void Process()
|
||||||
|
{
|
||||||
|
ListTemplates();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ListTemplates()
|
||||||
{
|
{
|
||||||
var data = _guideService.LoadTemplateData();
|
var data = _guideService.LoadTemplateData();
|
||||||
|
|
@ -1,7 +0,0 @@
|
|||||||
namespace Recyclarr.TrashLib.Config.Listers;
|
|
||||||
|
|
||||||
public enum ConfigCategory
|
|
||||||
{
|
|
||||||
Local,
|
|
||||||
Templates
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
namespace Recyclarr.TrashLib.Config.Listers;
|
|
||||||
|
|
||||||
public interface IConfigLister
|
|
||||||
{
|
|
||||||
void List();
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
using Recyclarr.Cli.Processors.Config;
|
|
||||||
using Recyclarr.TestLibrary.Autofac;
|
|
||||||
using Recyclarr.TrashLib.Config.Listers;
|
|
||||||
|
|
||||||
namespace Recyclarr.Cli.Tests.Processors;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
[Parallelizable(ParallelScope.All)]
|
|
||||||
public class ConfigListProcessorTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
[InlineAutoMockData(ConfigCategory.Templates)]
|
|
||||||
public void List_templates_invokes_correct_lister(
|
|
||||||
ConfigCategory category,
|
|
||||||
[Frozen(Matching.ImplementedInterfaces)] StubAutofacIndex<ConfigCategory, IConfigLister> configListers,
|
|
||||||
IConfigLister lister,
|
|
||||||
ConfigListProcessor sut)
|
|
||||||
{
|
|
||||||
configListers.Add(category, lister);
|
|
||||||
|
|
||||||
sut.Process(category);
|
|
||||||
|
|
||||||
lister.Received().List();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
using Autofac.Features.Indexed;
|
|
||||||
using Recyclarr.TrashLib.Config.Listers;
|
|
||||||
using Recyclarr.TrashLib.TestLibrary;
|
|
||||||
|
|
||||||
namespace Recyclarr.TrashLib.Tests.Config;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
[Parallelizable(ParallelScope.All)]
|
|
||||||
public class ConfigAutofacModuleTest : TrashLibIntegrationFixture
|
|
||||||
{
|
|
||||||
private static IEnumerable<ConfigCategory> AllConfigListCategories()
|
|
||||||
{
|
|
||||||
return Enum.GetValues<ConfigCategory>();
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestCaseSource(nameof(AllConfigListCategories))]
|
|
||||||
public void All_list_category_types_registered(ConfigCategory category)
|
|
||||||
{
|
|
||||||
var sut = Resolve<IIndex<ConfigCategory, IConfigLister>>();
|
|
||||||
var result = sut.TryGetValue(category, out _);
|
|
||||||
result.Should().BeTrue();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue