From de3bf08543ec4ec8c825fe9265324f7ef034bfec Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Mon, 9 Jan 2023 10:39:44 -0600 Subject: [PATCH] fix: Update local repo before running commands that need it --- .../Console/Commands/ListCustomFormatsCommand.cs | 11 ++++++++--- .../Console/Commands/ListQualitiesCommand.cs | 11 ++++++++--- .../Console/Commands/ListReleaseProfilesCommand.cs | 12 +++++++++--- src/Recyclarr.Cli/Console/Commands/RadarrCommand.cs | 11 ++++++++--- src/Recyclarr.Cli/Console/Commands/SonarrCommand.cs | 11 ++++++++--- src/Recyclarr.Cli/Console/Commands/SyncCommand.cs | 5 +++++ 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/Recyclarr.Cli/Console/Commands/ListCustomFormatsCommand.cs b/src/Recyclarr.Cli/Console/Commands/ListCustomFormatsCommand.cs index 88ce5631..57d9cce8 100644 --- a/src/Recyclarr.Cli/Console/Commands/ListCustomFormatsCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/ListCustomFormatsCommand.cs @@ -5,6 +5,7 @@ using JetBrains.Annotations; using Recyclarr.Cli.Console.Commands.Shared; using Recyclarr.Cli.Console.Helpers; using Recyclarr.TrashLib.Config; +using Recyclarr.TrashLib.Repo; using Recyclarr.TrashLib.Services.Common; using Spectre.Console.Cli; @@ -14,10 +15,11 @@ namespace Recyclarr.Cli.Console.Commands; [UsedImplicitly] [Description("List custom formats in the guide for a particular service.")] -internal class ListCustomFormatsCommand : Command +internal class ListCustomFormatsCommand : AsyncCommand { private readonly IGuideDataLister _lister; private readonly IIndex _guideService; + private readonly IRepoUpdater _repoUpdater; [UsedImplicitly] [SuppressMessage("Design", "CA1034:Nested types should not be visible")] @@ -31,14 +33,17 @@ internal class ListCustomFormatsCommand : Command guideService) + IIndex guideService, + IRepoUpdater repoUpdater) { _lister = lister; _guideService = guideService; + _repoUpdater = repoUpdater; } - public override int Execute(CommandContext context, CliSettings settings) + public override async Task ExecuteAsync(CommandContext context, CliSettings settings) { + await _repoUpdater.UpdateRepo(); var guideService = _guideService[settings.Service]; _lister.ListCustomFormats(guideService.GetCustomFormatData()); return 0; diff --git a/src/Recyclarr.Cli/Console/Commands/ListQualitiesCommand.cs b/src/Recyclarr.Cli/Console/Commands/ListQualitiesCommand.cs index 6aca7b6b..a04f4be7 100644 --- a/src/Recyclarr.Cli/Console/Commands/ListQualitiesCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/ListQualitiesCommand.cs @@ -5,6 +5,7 @@ using JetBrains.Annotations; using Recyclarr.Cli.Console.Commands.Shared; using Recyclarr.Cli.Console.Helpers; using Recyclarr.TrashLib.Config; +using Recyclarr.TrashLib.Repo; using Recyclarr.TrashLib.Services.Common; using Spectre.Console.Cli; @@ -13,10 +14,11 @@ namespace Recyclarr.Cli.Console.Commands; #pragma warning disable CS8765 [UsedImplicitly] [Description("List quality definitions in the guide for a particular service.")] -internal class ListQualitiesCommand : Command +internal class ListQualitiesCommand : AsyncCommand { private readonly IGuideDataLister _lister; private readonly IIndex _guideService; + private readonly IRepoUpdater _repoUpdater; [UsedImplicitly] [SuppressMessage("Design", "CA1034:Nested types should not be visible")] @@ -30,14 +32,17 @@ internal class ListQualitiesCommand : Command public ListQualitiesCommand( IGuideDataLister lister, - IIndex guideService) + IIndex guideService, + IRepoUpdater repoUpdater) { _lister = lister; _guideService = guideService; + _repoUpdater = repoUpdater; } - public override int Execute(CommandContext context, CliSettings settings) + public override async Task ExecuteAsync(CommandContext context, CliSettings settings) { + await _repoUpdater.UpdateRepo(); var guideService = _guideService[settings.Service]; _lister.ListQualities(guideService.GetQualities()); return 0; diff --git a/src/Recyclarr.Cli/Console/Commands/ListReleaseProfilesCommand.cs b/src/Recyclarr.Cli/Console/Commands/ListReleaseProfilesCommand.cs index 7a5a9455..312b46ff 100644 --- a/src/Recyclarr.Cli/Console/Commands/ListReleaseProfilesCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/ListReleaseProfilesCommand.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using JetBrains.Annotations; using Recyclarr.Cli.Console.Commands.Shared; +using Recyclarr.TrashLib.Repo; using Recyclarr.TrashLib.Services.Sonarr; using Serilog; using Spectre.Console.Cli; @@ -12,10 +13,11 @@ namespace Recyclarr.Cli.Console.Commands; [UsedImplicitly] [Description("List Sonarr release profiles in the guide for a particular service.")] -internal class ListReleaseProfilesCommand : Command +internal class ListReleaseProfilesCommand : AsyncCommand { private readonly ILogger _log; private readonly ISonarrGuideDataLister _lister; + private readonly IRepoUpdater _repoUpdater; [UsedImplicitly] [SuppressMessage("Design", "CA1034:Nested types should not be visible")] @@ -31,16 +33,20 @@ internal class ListReleaseProfilesCommand : Command ExecuteAsync(CommandContext context, CliSettings settings) { try { + await _repoUpdater.UpdateRepo(); + if (settings.ListTerms is not null) { // Ignore nullability of ListTerms since the Settings.Validate() method will check for null/empty. diff --git a/src/Recyclarr.Cli/Console/Commands/RadarrCommand.cs b/src/Recyclarr.Cli/Console/Commands/RadarrCommand.cs index c8cb1930..93b07d3f 100644 --- a/src/Recyclarr.Cli/Console/Commands/RadarrCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/RadarrCommand.cs @@ -6,6 +6,7 @@ using Recyclarr.Cli.Console.Commands.Shared; using Recyclarr.Cli.Console.Helpers; using Recyclarr.Cli.Migration; using Recyclarr.TrashLib.Config; +using Recyclarr.TrashLib.Repo; using Recyclarr.TrashLib.Services.Processors; using Recyclarr.TrashLib.Services.Radarr; using Serilog; @@ -20,6 +21,7 @@ internal class RadarrCommand : AsyncCommand private readonly ILogger _log; private readonly IRadarrGuideDataLister _lister; private readonly IMigrationExecutor _migration; + private readonly IRepoUpdater _repoUpdater; private readonly ISyncProcessor _syncProcessor; [UsedImplicitly] @@ -58,11 +60,13 @@ internal class RadarrCommand : AsyncCommand ILogger log, IRadarrGuideDataLister lister, IMigrationExecutor migration, + IRepoUpdater repoUpdater, ISyncProcessor syncProcessor) { _log = log; _lister = lister; _migration = migration; + _repoUpdater = repoUpdater; _syncProcessor = syncProcessor; } @@ -70,6 +74,10 @@ internal class RadarrCommand : AsyncCommand { _log.Warning("The `radarr` subcommand is DEPRECATED -- Use `sync` instead!"); + // Will throw if migration is required, otherwise just a warning is issued. + _migration.CheckNeededMigrations(); + await _repoUpdater.UpdateRepo(); + if (settings.ListCustomFormats) { _lister.ListCustomFormats(); @@ -82,9 +90,6 @@ internal class RadarrCommand : AsyncCommand return 0; } - // Will throw if migration is required, otherwise just a warning is issued. - _migration.CheckNeededMigrations(); - return (int) await _syncProcessor.ProcessConfigs(settings); } } diff --git a/src/Recyclarr.Cli/Console/Commands/SonarrCommand.cs b/src/Recyclarr.Cli/Console/Commands/SonarrCommand.cs index 064f22f1..73198baf 100644 --- a/src/Recyclarr.Cli/Console/Commands/SonarrCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/SonarrCommand.cs @@ -6,6 +6,7 @@ using Recyclarr.Cli.Console.Commands.Shared; using Recyclarr.Cli.Console.Helpers; using Recyclarr.Cli.Migration; using Recyclarr.TrashLib.Config; +using Recyclarr.TrashLib.Repo; using Recyclarr.TrashLib.Services.Processors; using Recyclarr.TrashLib.Services.Sonarr; using Serilog; @@ -21,6 +22,7 @@ internal class SonarrCommand : AsyncCommand private readonly ILogger _log; private readonly ISonarrGuideDataLister _lister; private readonly IMigrationExecutor _migration; + private readonly IRepoUpdater _repoUpdater; private readonly ISyncProcessor _syncProcessor; [UsedImplicitly] @@ -84,11 +86,13 @@ internal class SonarrCommand : AsyncCommand ILogger log, ISonarrGuideDataLister lister, IMigrationExecutor migration, + IRepoUpdater repoUpdater, ISyncProcessor syncProcessor) { _log = log; _lister = lister; _migration = migration; + _repoUpdater = repoUpdater; _syncProcessor = syncProcessor; } @@ -96,6 +100,10 @@ internal class SonarrCommand : AsyncCommand { _log.Warning("The `sonarr` subcommand is DEPRECATED -- Use `sync` instead!"); + // Will throw if migration is required, otherwise just a warning is issued. + _migration.CheckNeededMigrations(); + await _repoUpdater.UpdateRepo(); + if (settings.ListCustomFormats) { _lister.ListCustomFormats(); @@ -121,9 +129,6 @@ internal class SonarrCommand : AsyncCommand return 0; } - // Will throw if migration is required, otherwise just a warning is issued. - _migration.CheckNeededMigrations(); - return (int) await _syncProcessor.ProcessConfigs(settings); } } diff --git a/src/Recyclarr.Cli/Console/Commands/SyncCommand.cs b/src/Recyclarr.Cli/Console/Commands/SyncCommand.cs index c4f86e38..13dda9aa 100644 --- a/src/Recyclarr.Cli/Console/Commands/SyncCommand.cs +++ b/src/Recyclarr.Cli/Console/Commands/SyncCommand.cs @@ -6,6 +6,7 @@ using Recyclarr.Cli.Console.Commands.Shared; using Recyclarr.Cli.Console.Helpers; using Recyclarr.Cli.Migration; using Recyclarr.TrashLib.Config; +using Recyclarr.TrashLib.Repo; using Recyclarr.TrashLib.Services.Processors; using Spectre.Console.Cli; @@ -16,6 +17,7 @@ namespace Recyclarr.Cli.Console.Commands; public class SyncCommand : AsyncCommand { private readonly IMigrationExecutor _migration; + private readonly IRepoUpdater _repoUpdater; private readonly ISyncProcessor _syncProcessor; [UsedImplicitly] @@ -50,9 +52,11 @@ public class SyncCommand : AsyncCommand public SyncCommand( IMigrationExecutor migration, + IRepoUpdater repoUpdater, ISyncProcessor syncProcessor) { _migration = migration; + _repoUpdater = repoUpdater; _syncProcessor = syncProcessor; } @@ -61,6 +65,7 @@ public class SyncCommand : AsyncCommand { // Will throw if migration is required, otherwise just a warning is issued. _migration.CheckNeededMigrations(); + await _repoUpdater.UpdateRepo(); return (int) await _syncProcessor.ProcessConfigs(settings); }