refactor: Move app path creation to DefaultAppDataSetup

pull/254/head
Robert Dailey 1 year ago
parent 42fd401aff
commit eb5b34f5cd

@ -98,11 +98,10 @@ public static class CompositionRoot
private static void CliRegistrations(ContainerBuilder builder)
{
builder.RegisterType<BaseCommandSetupInterceptor>().As<ICommandInterceptor>();
builder.RegisterType<VersionLogInterceptor>().As<ICommandInterceptor>();
builder.RegisterType<ProgramInformationLogInterceptor>().As<ICommandInterceptor>();
builder.RegisterType<GlobalTaskInterceptor>().As<ICommandInterceptor>();
builder.RegisterTypes(
typeof(AppPathSetupTask),
typeof(JanitorCleanupTask))
.As<IGlobalSetupTask>()
.OrderByRegistration();

@ -1,11 +1,13 @@
using Recyclarr.Platform;
using Spectre.Console.Cli;
namespace Recyclarr.Cli.Console.Interceptors;
public class VersionLogInterceptor(ILogger log) : ICommandInterceptor
public class ProgramInformationLogInterceptor(ILogger log, IAppPaths paths) : ICommandInterceptor
{
public void Intercept(CommandContext context, CommandSettings settings)
{
log.Debug("Recyclarr Version: {Version}", GitVersionInformation.InformationalVersion);
log.Debug("App Data Dir: {AppData}", paths.AppDataDirectory);
}
}

@ -1,23 +0,0 @@
using Recyclarr.Platform;
namespace Recyclarr.Cli.Console.Setup;
public class AppPathSetupTask(ILogger log, IAppPaths paths) : IGlobalSetupTask
{
public void OnStart()
{
log.Debug("App Data Dir: {AppData}", paths.AppDataDirectory);
// Initialize other directories used throughout the application
// Do not initialize the repo directory here; the GitRepositoryFactory handles that later.
paths.CacheDirectory.Create();
paths.LogDirectory.Create();
paths.ConfigsDirectory.Create();
paths.IncludesDirectory.Create();
}
public void OnFinish()
{
// No work to do for this event
}
}

@ -9,7 +9,16 @@ public class DefaultAppDataSetup(IEnvironment env, IFileSystem fs) : IAppDataSet
public IAppPaths CreateAppPaths()
{
var appDir = GetAppDataDirectory(AppDataDirectoryOverride);
return new AppPaths(fs.DirectoryInfo.New(appDir));
var paths = new AppPaths(fs.DirectoryInfo.New(appDir));
// Initialize other directories used throughout the application
// Do not initialize the repo directory here; the GitRepositoryFactory handles that later.
paths.CacheDirectory.Create();
paths.LogDirectory.Create();
paths.ConfigsDirectory.Create();
paths.IncludesDirectory.Create();
return paths;
}
private string GetAppDataDirectory(string? appDataDirectoryOverride)

@ -1,7 +1,6 @@
using System.IO.Abstractions;
using Recyclarr.Cli.Console.Setup;
using Recyclarr.Settings;
using Recyclarr.TestLibrary;
namespace Recyclarr.Cli.IntegrationTests;
@ -14,8 +13,7 @@ internal class BaseCommandSetupIntegrationTest : CliIntegrationFixture
var registrations = Resolve<IEnumerable<IGlobalSetupTask>>();
registrations.Select(x => x.GetType()).Should().BeEquivalentTo(new[]
{
typeof(JanitorCleanupTask),
typeof(AppPathSetupTask)
typeof(JanitorCleanupTask)
});
}
@ -60,26 +58,4 @@ internal class BaseCommandSetupIntegrationTest : CliIntegrationFixture
Fs.AllFiles.Where(x => x.StartsWith(Paths.LogDirectory.FullName))
.Should().HaveCount(maxFiles);
}
[Test]
public void App_paths_setup_creates_initial_directories()
{
for (var i = 0; i < 50; ++i)
{
Fs.AddFile(Paths.LogDirectory.File($"logfile-{i}.log").FullName, new MockFileData(""));
}
var sut = Resolve<AppPathSetupTask>();
sut.OnStart();
var expectedDirs = new[]
{
Paths.CacheDirectory.FullName,
Paths.LogDirectory.FullName,
Paths.ConfigsDirectory.FullName,
Paths.IncludesDirectory.FullName
};
Fs.LeafDirectories().Should().BeEquivalentTo(expectedDirs);
}
}

Loading…
Cancel
Save