feat: `config list local` implemented

pull/201/head
Robert Dailey 2 years ago
parent ce481e0d1f
commit e54cef0859

@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="config list local" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/Recyclarr.Cli/bin/Debug/net7.0/recyclarr" />
<option name="PROGRAM_PARAMETERS" value="config list local" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Recyclarr.Cli/bin/Debug/net7.0" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/Recyclarr.Cli/Recyclarr.Cli.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net7.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>

@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="config list templates" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/Recyclarr.Cli/bin/Debug/net7.0/recyclarr.exe" />
<option name="EXE_PATH" value="$PROJECT_DIR$/Recyclarr.Cli/bin/Debug/net7.0/recyclarr" />
<option name="PROGRAM_PARAMETERS" value="config list templates" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Recyclarr.Cli/bin/Debug/net7.0" />
<option name="PASS_PARENT_ENVS" value="1" />

@ -5,7 +5,6 @@ using Recyclarr.Cli.Console.Helpers;
using Recyclarr.TrashLib.Config.Listers;
using Recyclarr.TrashLib.ExceptionTypes;
using Recyclarr.TrashLib.Processors;
using Recyclarr.TrashLib.Repo;
using Spectre.Console.Cli;
namespace Recyclarr.Cli.Console.Commands;
@ -16,7 +15,6 @@ public class ConfigListCommand : AsyncCommand<ConfigListCommand.CliSettings>
{
private readonly ILogger _log;
private readonly ConfigListProcessor _processor;
private readonly IRepoUpdater _repoUpdater;
[SuppressMessage("Design", "CA1034:Nested types should not be visible")]
public class CliSettings : BaseCommandSettings
@ -26,20 +24,17 @@ public class ConfigListCommand : AsyncCommand<ConfigListCommand.CliSettings>
public ConfigListCategory ListCategory { get; [UsedImplicitly] init; } = ConfigListCategory.Local;
}
public ConfigListCommand(ILogger log, ConfigListProcessor processor, IRepoUpdater repoUpdater)
public ConfigListCommand(ILogger log, ConfigListProcessor processor)
{
_log = log;
_processor = processor;
_repoUpdater = repoUpdater;
}
public override async Task<int> ExecuteAsync(CommandContext context, CliSettings settings)
{
await _repoUpdater.UpdateRepo();
try
{
_processor.Process(settings.ListCategory);
await _processor.Process(settings.ListCategory);
}
catch (FileExistsException e)
{

@ -1,18 +1,83 @@
using System.IO.Abstractions;
using Recyclarr.TrashLib.Config.Parsing;
using Recyclarr.TrashLib.Startup;
using Spectre.Console;
using Spectre.Console.Rendering;
namespace Recyclarr.TrashLib.Config.Listers;
public class ConfigLocalLister : IConfigLister
{
private readonly IAnsiConsole _console;
private readonly IConfigurationFinder _configFinder;
private readonly IConfigurationLoader _configLoader;
private readonly IAppPaths _paths;
public ConfigLocalLister(IAnsiConsole console)
public ConfigLocalLister(
IAnsiConsole console,
IConfigurationFinder configFinder,
IConfigurationLoader configLoader,
IAppPaths paths)
{
_console = console;
_configFinder = configFinder;
_configLoader = configLoader;
_paths = paths;
}
public void List()
public Task List()
{
_console.Write("Local listing is not supported yet, but coming soon.");
var tree = new Tree(_paths.AppDataDirectory.ToString()!);
foreach (var configPath in _configFinder.GetConfigFiles())
{
var configs = _configLoader.Load(configPath);
var rows = new List<IRenderable>();
BuildInstanceTree(rows, configs, SupportedServices.Radarr);
BuildInstanceTree(rows, configs, SupportedServices.Sonarr);
if (!rows.Any())
{
rows.Add(new Markup("([red]Empty[/])"));
}
var configTree = new Tree(Markup.FromInterpolated($"[b]{MakeRelative(configPath)}[/]"));
foreach (var r in rows)
{
configTree.AddNode(r);
}
tree.AddNode(configTree);
}
_console.WriteLine();
_console.Write(tree);
return Task.CompletedTask;
}
private string MakeRelative(IFileInfo path)
{
var configPath = new Uri(path.FullName, UriKind.Absolute);
var configDir = new Uri(_paths.ConfigsDirectory.FullName, UriKind.Absolute);
return configDir.MakeRelativeUri(configPath).ToString();
}
private static void BuildInstanceTree(
ICollection<IRenderable> rows,
IConfigRegistry registry,
SupportedServices service)
{
var configs = registry.GetConfigsOfType(service).ToList();
if (!configs.Any())
{
return;
}
var tree = new Tree(Markup.FromInterpolated($"[red]{service}[/]"));
tree.AddNodes(configs.Select(c =>
Markup.FromInterpolated($"[blue]{c.InstanceName ?? c.BaseUrl.ToString()}[/]")));
rows.Add(tree);
}
}

@ -1,5 +1,6 @@
using MoreLinq;
using Recyclarr.TrashLib.Config.Services;
using Recyclarr.TrashLib.Repo;
using Spectre.Console;
namespace Recyclarr.TrashLib.Config.Listers;
@ -8,15 +9,22 @@ public class ConfigTemplateLister : IConfigLister
{
private readonly IAnsiConsole _console;
private readonly IConfigTemplateGuideService _guideService;
private readonly IRepoUpdater _repoUpdater;
public ConfigTemplateLister(IAnsiConsole console, IConfigTemplateGuideService guideService)
public ConfigTemplateLister(
IAnsiConsole console,
IConfigTemplateGuideService guideService,
IRepoUpdater repoUpdater)
{
_console = console;
_guideService = guideService;
_repoUpdater = repoUpdater;
}
public void List()
public async Task List()
{
await _repoUpdater.UpdateRepo();
var data = _guideService.TemplateData;
var table = new Table();

@ -2,5 +2,5 @@ namespace Recyclarr.TrashLib.Config.Listers;
public interface IConfigLister
{
void List();
Task List();
}

@ -13,7 +13,12 @@ public class ConfigRegistry : IConfigRegistry
_configs.GetOrCreate(config.ServiceType).Add(config);
}
private IEnumerable<IServiceConfiguration> GetConfigsOfType(SupportedServices? serviceType)
public IEnumerable<IServiceConfiguration> GetAllConfigs()
{
return GetConfigsOfType(null);
}
public IEnumerable<IServiceConfiguration> GetConfigsOfType(SupportedServices? serviceType)
{
return _configs
.Where(x => serviceType is null || serviceType.Value == x.Key)

@ -29,7 +29,7 @@ public class ConfigurationFinder : IConfigurationFinder
return configs;
}
public IReadOnlyCollection<IFileInfo> GetConfigFiles(IReadOnlyCollection<IFileInfo>? configs)
public IReadOnlyCollection<IFileInfo> GetConfigFiles(IReadOnlyCollection<IFileInfo>? configs = null)
{
if (configs is not null && configs.Any())
{

@ -8,4 +8,6 @@ public interface IConfigRegistry
int Count { get; }
bool DoesConfigExist(string name);
IEnumerable<IServiceConfiguration> GetConfigsBasedOnSettings(ISyncSettings settings);
IEnumerable<IServiceConfiguration> GetAllConfigs();
IEnumerable<IServiceConfiguration> GetConfigsOfType(SupportedServices? serviceType);
}

@ -4,5 +4,5 @@ namespace Recyclarr.TrashLib.Config.Parsing;
public interface IConfigurationFinder
{
IReadOnlyCollection<IFileInfo> GetConfigFiles(IReadOnlyCollection<IFileInfo>? configs);
IReadOnlyCollection<IFileInfo> GetConfigFiles(IReadOnlyCollection<IFileInfo>? configs = null);
}

@ -14,7 +14,7 @@ public class ConfigListProcessor
_configListers = configListers;
}
public void Process(ConfigListCategory listCategory)
public async Task Process(ConfigListCategory listCategory)
{
_log.Debug("Listing configuration for category {Category}", listCategory);
if (!_configListers.TryGetValue(listCategory, out var lister))
@ -22,6 +22,6 @@ public class ConfigListProcessor
throw new ArgumentOutOfRangeException(nameof(listCategory), listCategory, "Unknown list category");
}
lister.List();
await lister.List();
}
}

Loading…
Cancel
Save