diff --git a/src/.idea/.idea.Recyclarr/.idea/runConfigurations/config_list_local.xml b/src/.idea/.idea.Recyclarr/.idea/runConfigurations/config_list_local.xml
new file mode 100644
index 00000000..e0ae3eac
--- /dev/null
+++ b/src/.idea/.idea.Recyclarr/.idea/runConfigurations/config_list_local.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/.idea/.idea.Recyclarr/.idea/runConfigurations/config_list_templates.xml b/src/.idea/.idea.Recyclarr/.idea/runConfigurations/config_list_templates.xml
index c696e2c1..ff5c8beb 100644
--- a/src/.idea/.idea.Recyclarr/.idea/runConfigurations/config_list_templates.xml
+++ b/src/.idea/.idea.Recyclarr/.idea/runConfigurations/config_list_templates.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/src/Recyclarr.Cli/Console/Commands/ConfigListCommand.cs b/src/Recyclarr.Cli/Console/Commands/ConfigListCommand.cs
index 3468ae02..9404d4be 100644
--- a/src/Recyclarr.Cli/Console/Commands/ConfigListCommand.cs
+++ b/src/Recyclarr.Cli/Console/Commands/ConfigListCommand.cs
@@ -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
{
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
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 ExecuteAsync(CommandContext context, CliSettings settings)
{
- await _repoUpdater.UpdateRepo();
-
try
{
- _processor.Process(settings.ListCategory);
+ await _processor.Process(settings.ListCategory);
}
catch (FileExistsException e)
{
diff --git a/src/Recyclarr.TrashLib/Config/Listers/ConfigLocalLister.cs b/src/Recyclarr.TrashLib/Config/Listers/ConfigLocalLister.cs
index 1a1f2817..ff75e4e2 100644
--- a/src/Recyclarr.TrashLib/Config/Listers/ConfigLocalLister.cs
+++ b/src/Recyclarr.TrashLib/Config/Listers/ConfigLocalLister.cs
@@ -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();
+ 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 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);
}
}
diff --git a/src/Recyclarr.TrashLib/Config/Listers/ConfigTemplateLister.cs b/src/Recyclarr.TrashLib/Config/Listers/ConfigTemplateLister.cs
index 51fa61ef..b1ff7b62 100644
--- a/src/Recyclarr.TrashLib/Config/Listers/ConfigTemplateLister.cs
+++ b/src/Recyclarr.TrashLib/Config/Listers/ConfigTemplateLister.cs
@@ -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();
diff --git a/src/Recyclarr.TrashLib/Config/Listers/IConfigLister.cs b/src/Recyclarr.TrashLib/Config/Listers/IConfigLister.cs
index 411b193c..fd2221e5 100644
--- a/src/Recyclarr.TrashLib/Config/Listers/IConfigLister.cs
+++ b/src/Recyclarr.TrashLib/Config/Listers/IConfigLister.cs
@@ -2,5 +2,5 @@ namespace Recyclarr.TrashLib.Config.Listers;
public interface IConfigLister
{
- void List();
+ Task List();
}
diff --git a/src/Recyclarr.TrashLib/Config/Parsing/ConfigRegistry.cs b/src/Recyclarr.TrashLib/Config/Parsing/ConfigRegistry.cs
index c105bf30..deabfd9e 100644
--- a/src/Recyclarr.TrashLib/Config/Parsing/ConfigRegistry.cs
+++ b/src/Recyclarr.TrashLib/Config/Parsing/ConfigRegistry.cs
@@ -13,7 +13,12 @@ public class ConfigRegistry : IConfigRegistry
_configs.GetOrCreate(config.ServiceType).Add(config);
}
- private IEnumerable GetConfigsOfType(SupportedServices? serviceType)
+ public IEnumerable GetAllConfigs()
+ {
+ return GetConfigsOfType(null);
+ }
+
+ public IEnumerable GetConfigsOfType(SupportedServices? serviceType)
{
return _configs
.Where(x => serviceType is null || serviceType.Value == x.Key)
diff --git a/src/Recyclarr.TrashLib/Config/Parsing/ConfigurationFinder.cs b/src/Recyclarr.TrashLib/Config/Parsing/ConfigurationFinder.cs
index f2f0952d..a9a80cab 100644
--- a/src/Recyclarr.TrashLib/Config/Parsing/ConfigurationFinder.cs
+++ b/src/Recyclarr.TrashLib/Config/Parsing/ConfigurationFinder.cs
@@ -29,7 +29,7 @@ public class ConfigurationFinder : IConfigurationFinder
return configs;
}
- public IReadOnlyCollection GetConfigFiles(IReadOnlyCollection? configs)
+ public IReadOnlyCollection GetConfigFiles(IReadOnlyCollection? configs = null)
{
if (configs is not null && configs.Any())
{
diff --git a/src/Recyclarr.TrashLib/Config/Parsing/IConfigRegistry.cs b/src/Recyclarr.TrashLib/Config/Parsing/IConfigRegistry.cs
index 830baee4..f7e8d68a 100644
--- a/src/Recyclarr.TrashLib/Config/Parsing/IConfigRegistry.cs
+++ b/src/Recyclarr.TrashLib/Config/Parsing/IConfigRegistry.cs
@@ -8,4 +8,6 @@ public interface IConfigRegistry
int Count { get; }
bool DoesConfigExist(string name);
IEnumerable GetConfigsBasedOnSettings(ISyncSettings settings);
+ IEnumerable GetAllConfigs();
+ IEnumerable GetConfigsOfType(SupportedServices? serviceType);
}
diff --git a/src/Recyclarr.TrashLib/Config/Parsing/IConfigurationFinder.cs b/src/Recyclarr.TrashLib/Config/Parsing/IConfigurationFinder.cs
index 6769bd28..51c69bfb 100644
--- a/src/Recyclarr.TrashLib/Config/Parsing/IConfigurationFinder.cs
+++ b/src/Recyclarr.TrashLib/Config/Parsing/IConfigurationFinder.cs
@@ -4,5 +4,5 @@ namespace Recyclarr.TrashLib.Config.Parsing;
public interface IConfigurationFinder
{
- IReadOnlyCollection GetConfigFiles(IReadOnlyCollection? configs);
+ IReadOnlyCollection GetConfigFiles(IReadOnlyCollection? configs = null);
}
diff --git a/src/Recyclarr.TrashLib/Processors/ConfigListProcessor.cs b/src/Recyclarr.TrashLib/Processors/ConfigListProcessor.cs
index 3dc8a14c..4ac4f343 100644
--- a/src/Recyclarr.TrashLib/Processors/ConfigListProcessor.cs
+++ b/src/Recyclarr.TrashLib/Processors/ConfigListProcessor.cs
@@ -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();
}
}