diff --git a/src/Recyclarr.Tests/Migration/MigrationExecutorTest.cs b/src/Recyclarr.Tests/Migration/MigrationExecutorTest.cs index f541611f..c6b0f6a9 100644 --- a/src/Recyclarr.Tests/Migration/MigrationExecutorTest.cs +++ b/src/Recyclarr.Tests/Migration/MigrationExecutorTest.cs @@ -36,10 +36,10 @@ public class MigrationExecutorTest step.CheckIfNeeded().Returns(false); - executor.PerformAllMigrationSteps(); + executor.PerformAllMigrationSteps(false); step.Received().CheckIfNeeded(); - step.DidNotReceive().Execute(); + step.DidNotReceive().Execute(null); } [Test] @@ -51,10 +51,10 @@ public class MigrationExecutorTest step.CheckIfNeeded().Returns(true); - executor.PerformAllMigrationSteps(); + executor.PerformAllMigrationSteps(false); step.Received().CheckIfNeeded(); - step.Received().Execute(); + step.Received().Execute(null); } [Test] @@ -75,7 +75,7 @@ public class MigrationExecutorTest var executor = new MigrationExecutor(steps, console); - executor.PerformAllMigrationSteps(); + executor.PerformAllMigrationSteps(false); Received.InOrder(() => { @@ -93,9 +93,9 @@ public class MigrationExecutorTest var executor = new MigrationExecutor(new[] {step}, console); step.CheckIfNeeded().Returns(true); - step.When(x => x.Execute()).Throw(new ArgumentException("test message")); + step.When(x => x.Execute(null)).Throw(new ArgumentException("test message")); - var act = () => executor.PerformAllMigrationSteps(); + var act = () => executor.PerformAllMigrationSteps(false); act.Should().Throw().Which.OriginalException.Message.Should().Be("test message"); } @@ -109,9 +109,9 @@ public class MigrationExecutorTest var exception = new MigrationException(new Exception(), "a", new[] {"b"}); step.CheckIfNeeded().Returns(true); - step.When(x => x.Execute()).Throw(exception); + step.When(x => x.Execute(null)).Throw(exception); - var act = () => executor.PerformAllMigrationSteps(); + var act = () => executor.PerformAllMigrationSteps(false); act.Should().Throw().Which.Should().Be(exception); } diff --git a/src/Recyclarr.Tests/Migration/Steps/MigrateTrashUpdaterAppDataDirTest.cs b/src/Recyclarr.Tests/Migration/Steps/MigrateTrashUpdaterAppDataDirTest.cs index 80b1c5b5..d2f92d95 100644 --- a/src/Recyclarr.Tests/Migration/Steps/MigrateTrashUpdaterAppDataDirTest.cs +++ b/src/Recyclarr.Tests/Migration/Steps/MigrateTrashUpdaterAppDataDirTest.cs @@ -40,7 +40,7 @@ public class MigrateTrashUpdaterAppDataDirTest fs.AddDirectory(Path.Combine(BasePath, "trash-updater")); fs.AddDirectory(Path.Combine(BasePath, "recyclarr")); - var act = sut.Execute; + var act = () => sut.Execute(null); act.Should().Throw(); } @@ -54,7 +54,7 @@ public class MigrateTrashUpdaterAppDataDirTest // Add file instead of directory since the migration step only operates on files fs.AddFile(fs.Path.Combine(paths.BasePath, "trash-updater", "1", "2", "test.txt"), new MockFileData("")); - sut.Execute(); + sut.Execute(null); fs.AllDirectories.Should().NotContain(x => x.Contains("trash-updater")); fs.AllFiles.Should().Contain(x => Regex.IsMatch(x, @"[/\\]recyclarr[/\\]1[/\\]2[/\\]test.txt$")); diff --git a/src/Recyclarr.Tests/Migration/Steps/MigrateTrashYmlTest.cs b/src/Recyclarr.Tests/Migration/Steps/MigrateTrashYmlTest.cs index 506a318a..7cc99f91 100644 --- a/src/Recyclarr.Tests/Migration/Steps/MigrateTrashYmlTest.cs +++ b/src/Recyclarr.Tests/Migration/Steps/MigrateTrashYmlTest.cs @@ -38,7 +38,7 @@ public class MigrateTrashYmlTest { fs.AddFile(Path.Combine(BasePath, "recyclarr.yml"), MockFileData.NullObject); - var act = () => sut.Execute(); + var act = () => sut.Execute(null); act.Should().Throw(); } @@ -51,7 +51,7 @@ public class MigrateTrashYmlTest const string expectedData = "fake contents"; fs.AddFile(Path.Combine(BasePath, "trash.yml"), expectedData); - sut.Execute(); + sut.Execute(null); fs.AllFiles.Should().ContainSingle(x => Regex.IsMatch(x, @"[/\\]recyclarr\.yml$")); } diff --git a/src/Recyclarr/Command/MigrateCommand.cs b/src/Recyclarr/Command/MigrateCommand.cs index d0e2a9eb..adac6a19 100644 --- a/src/Recyclarr/Command/MigrateCommand.cs +++ b/src/Recyclarr/Command/MigrateCommand.cs @@ -16,6 +16,10 @@ public class MigrateCommand : ICommand private readonly IMigrationExecutor _migration; private readonly IDefaultAppDataSetup _appDataSetup; + [CommandOption("debug", 'd', Description = + "Display additional logs useful for development/debug purposes.")] + public bool Debug { get; [UsedImplicitly] set; } = false; + public MigrateCommand(IMigrationExecutor migration, IDefaultAppDataSetup appDataSetup) { _migration = migration; @@ -33,7 +37,7 @@ public class MigrateCommand : ICommand { try { - _migration.PerformAllMigrationSteps(); + _migration.PerformAllMigrationSteps(Debug); } catch (MigrationException e) { diff --git a/src/Recyclarr/Migration/IMigrationExecutor.cs b/src/Recyclarr/Migration/IMigrationExecutor.cs index 2ee1a5b2..4335ee38 100644 --- a/src/Recyclarr/Migration/IMigrationExecutor.cs +++ b/src/Recyclarr/Migration/IMigrationExecutor.cs @@ -2,6 +2,6 @@ namespace Recyclarr.Migration; public interface IMigrationExecutor { - void PerformAllMigrationSteps(); + void PerformAllMigrationSteps(bool withDiagnostics); void CheckNeededMigrations(); } diff --git a/src/Recyclarr/Migration/IMigrationStep.cs b/src/Recyclarr/Migration/IMigrationStep.cs index 397e826c..81b89515 100644 --- a/src/Recyclarr/Migration/IMigrationStep.cs +++ b/src/Recyclarr/Migration/IMigrationStep.cs @@ -1,3 +1,5 @@ +using CliFx.Infrastructure; + namespace Recyclarr.Migration; public interface IMigrationStep @@ -7,5 +9,5 @@ public interface IMigrationStep IReadOnlyCollection Remediation { get; } bool Required { get; } bool CheckIfNeeded(); - void Execute(); + void Execute(IConsole? console); } diff --git a/src/Recyclarr/Migration/MigrationExecutor.cs b/src/Recyclarr/Migration/MigrationExecutor.cs index 6bcaca40..86463dea 100644 --- a/src/Recyclarr/Migration/MigrationExecutor.cs +++ b/src/Recyclarr/Migration/MigrationExecutor.cs @@ -14,7 +14,7 @@ public class MigrationExecutor : IMigrationExecutor _migrationSteps = migrationSteps.OrderBy(x => x.Order).ToList(); } - public void PerformAllMigrationSteps() + public void PerformAllMigrationSteps(bool withDiagnostics) { _console.Output.WriteLine("Performing migration steps..."); @@ -31,7 +31,7 @@ public class MigrationExecutor : IMigrationExecutor try { - step.Execute(); + step.Execute(withDiagnostics ? _console : null); } catch (Exception e) when (e is not MigrationException) { diff --git a/src/Recyclarr/Migration/Steps/MigrateTrashUpdaterAppDataDir.cs b/src/Recyclarr/Migration/Steps/MigrateTrashUpdaterAppDataDir.cs index 59a697a2..a9f8323b 100644 --- a/src/Recyclarr/Migration/Steps/MigrateTrashUpdaterAppDataDir.cs +++ b/src/Recyclarr/Migration/Steps/MigrateTrashUpdaterAppDataDir.cs @@ -1,4 +1,5 @@ using System.IO.Abstractions; +using CliFx.Infrastructure; using Common.Extensions; using JetBrains.Annotations; using TrashLib; @@ -41,5 +42,5 @@ public class MigrateTrashUpdaterAppDataDir : IMigrationStep public bool CheckIfNeeded() => _fs.Directory.Exists(GetOldPath()); - public void Execute() => _fs.MergeDirectory(GetOldPath(), GetNewPath()); + public void Execute(IConsole? console) => _fs.MergeDirectory(GetOldPath(), GetNewPath()); } diff --git a/src/Recyclarr/Migration/Steps/MigrateTrashYml.cs b/src/Recyclarr/Migration/Steps/MigrateTrashYml.cs index 456d7199..e9a9af74 100644 --- a/src/Recyclarr/Migration/Steps/MigrateTrashYml.cs +++ b/src/Recyclarr/Migration/Steps/MigrateTrashYml.cs @@ -1,4 +1,5 @@ using System.IO.Abstractions; +using CliFx.Infrastructure; using JetBrains.Annotations; namespace Recyclarr.Migration.Steps; @@ -35,7 +36,7 @@ public class MigrateTrashYml : IMigrationStep public bool CheckIfNeeded() => _fileSystem.File.Exists(_oldConfigPath); - public void Execute() + public void Execute(IConsole? console) { _fileSystem.File.Move(_oldConfigPath, _newConfigPath); }