diff --git a/CHANGELOG.md b/CHANGELOG.md index ff1c6c8d..0765a68d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- The `--app-data` option is now common to all commands. + +### Fixed + +- CLI: Commands no longer crash due to a null app data directory variable (#288). + ## [7.1.0] - 2024-07-10 ### Added diff --git a/src/Recyclarr.Cli/Console/Commands/BaseCommandSettings.cs b/src/Recyclarr.Cli/Console/Commands/BaseCommandSettings.cs index 0390c5b1..268b0c87 100644 --- a/src/Recyclarr.Cli/Console/Commands/BaseCommandSettings.cs +++ b/src/Recyclarr.Cli/Console/Commands/BaseCommandSettings.cs @@ -12,4 +12,9 @@ public class BaseCommandSettings : CommandSettings [Description("Show debug logs in console output.")] [UsedImplicitly(ImplicitUseKindFlags.Assign)] public bool Debug { get; init; } + + [CommandOption("--app-data")] + [Description("Custom path to the application data directory")] + [UsedImplicitly(ImplicitUseKindFlags.Assign)] + public string? AppData { get; init; } } diff --git a/src/Recyclarr.Cli/Console/Commands/DeleteCustomFormatsCommand.cs b/src/Recyclarr.Cli/Console/Commands/DeleteCustomFormatsCommand.cs index 5e8034b1..70815841 100644 --- a/src/Recyclarr.Cli/Console/Commands/DeleteCustomFormatsCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/DeleteCustomFormatsCommand.cs @@ -20,7 +20,7 @@ public class DeleteCustomFormatsCommand( [SuppressMessage("Design", "CA1034:Nested types should not be visible")] [SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Spectre.Console requires it")] - public class CliSettings : ServiceCommandSettings, IDeleteCustomFormatSettings + public class CliSettings : BaseCommandSettings, IDeleteCustomFormatSettings { [CommandArgument(0, "")] [Description("The name of the instance to delete CFs from.")] diff --git a/src/Recyclarr.Cli/Console/Commands/MigrateCommand.cs b/src/Recyclarr.Cli/Console/Commands/MigrateCommand.cs index 234543da..7c6ff757 100644 --- a/src/Recyclarr.Cli/Console/Commands/MigrateCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/MigrateCommand.cs @@ -18,7 +18,7 @@ public class MigrateCommand( { [UsedImplicitly] [SuppressMessage("Design", "CA1034:Nested types should not be visible")] - public class CliSettings : ServiceCommandSettings; + public class CliSettings : BaseCommandSettings; public override int Execute(CommandContext context, CliSettings settings) { diff --git a/src/Recyclarr.Cli/Console/Commands/ServiceCommand.cs b/src/Recyclarr.Cli/Console/Commands/ServiceCommand.cs deleted file mode 100644 index 8325e089..00000000 --- a/src/Recyclarr.Cli/Console/Commands/ServiceCommand.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.ComponentModel; -using JetBrains.Annotations; -using Spectre.Console.Cli; - -namespace Recyclarr.Cli.Console.Commands; - -public class ServiceCommandSettings : BaseCommandSettings -{ - [CommandOption("--app-data")] - [Description("Custom path to the application data directory")] - [UsedImplicitly(ImplicitUseKindFlags.Assign)] - public string? AppData { get; init; } -} diff --git a/src/Recyclarr.Cli/Console/Commands/SyncCommand.cs b/src/Recyclarr.Cli/Console/Commands/SyncCommand.cs index e3a9e575..1402078e 100644 --- a/src/Recyclarr.Cli/Console/Commands/SyncCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/SyncCommand.cs @@ -20,7 +20,7 @@ public class SyncCommand(IMigrationExecutor migration, IMultiRepoUpdater repoUpd [SuppressMessage("Design", "CA1034:Nested types should not be visible")] [SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Spectre.Console requires it")] - public class CliSettings : ServiceCommandSettings, ISyncSettings + public class CliSettings : BaseCommandSettings, ISyncSettings { [CommandArgument(0, "[service]")] [EnumDescription("The service to sync. If not specified, all services are synced.")] diff --git a/src/Recyclarr.Cli/Console/Helpers/CommandSetupInterceptor.cs b/src/Recyclarr.Cli/Console/Helpers/CommandSetupInterceptor.cs index e1f90193..11e1873e 100644 --- a/src/Recyclarr.Cli/Console/Helpers/CommandSetupInterceptor.cs +++ b/src/Recyclarr.Cli/Console/Helpers/CommandSetupInterceptor.cs @@ -31,10 +31,6 @@ internal sealed class CommandSetupInterceptor : ICommandInterceptor, IDisposable { switch (settings) { - case ServiceCommandSettings cmd: - HandleServiceCommand(cmd); - break; - case BaseCommandSettings cmd: HandleBaseCommand(cmd); break; @@ -48,15 +44,12 @@ internal sealed class CommandSetupInterceptor : ICommandInterceptor, IDisposable _taskExecutor.Value.OnFinish(); } - private void HandleServiceCommand(ServiceCommandSettings cmd) + private void HandleBaseCommand(BaseCommandSettings cmd) { - HandleBaseCommand(cmd); _appDataSetup.SetAppDataDirectoryOverride(cmd.AppData ?? ""); - } - private void HandleBaseCommand(BaseCommandSettings cmd) - { cmd.CancellationToken = _ct.Token; + _loggingLevelSwitch.MinimumLevel = cmd.Debug switch { true => LogEventLevel.Debug,