fix: --app-data is now common to all commands

This resolves a NRE because the app data override was not set
consistently by all commands.

Fixes #288.
docker-retention
Robert Dailey 7 months ago
parent 8f908556de
commit 6cac2ed5c2

@ -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

@ -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; }
}

@ -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, "<instance_name>")]
[Description("The name of the instance to delete CFs from.")]

@ -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)
{

@ -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; }
}

@ -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<SupportedServices>("The service to sync. If not specified, all services are synced.")]

@ -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,

Loading…
Cancel
Save