fix: Update local repo before running commands that need it

pull/201/head
Robert Dailey 1 year ago
parent 7c000b438b
commit de3bf08543

@ -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<ListCustomFormatsCommand.CliSettings>
internal class ListCustomFormatsCommand : AsyncCommand<ListCustomFormatsCommand.CliSettings>
{
private readonly IGuideDataLister _lister;
private readonly IIndex<SupportedServices, IGuideService> _guideService;
private readonly IRepoUpdater _repoUpdater;
[UsedImplicitly]
[SuppressMessage("Design", "CA1034:Nested types should not be visible")]
@ -31,14 +33,17 @@ internal class ListCustomFormatsCommand : Command<ListCustomFormatsCommand.CliSe
public ListCustomFormatsCommand(
IGuideDataLister lister,
IIndex<SupportedServices, IGuideService> guideService)
IIndex<SupportedServices, IGuideService> guideService,
IRepoUpdater repoUpdater)
{
_lister = lister;
_guideService = guideService;
_repoUpdater = repoUpdater;
}
public override int Execute(CommandContext context, CliSettings settings)
public override async Task<int> ExecuteAsync(CommandContext context, CliSettings settings)
{
await _repoUpdater.UpdateRepo();
var guideService = _guideService[settings.Service];
_lister.ListCustomFormats(guideService.GetCustomFormatData());
return 0;

@ -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<ListQualitiesCommand.CliSettings>
internal class ListQualitiesCommand : AsyncCommand<ListQualitiesCommand.CliSettings>
{
private readonly IGuideDataLister _lister;
private readonly IIndex<SupportedServices, IGuideService> _guideService;
private readonly IRepoUpdater _repoUpdater;
[UsedImplicitly]
[SuppressMessage("Design", "CA1034:Nested types should not be visible")]
@ -30,14 +32,17 @@ internal class ListQualitiesCommand : Command<ListQualitiesCommand.CliSettings>
public ListQualitiesCommand(
IGuideDataLister lister,
IIndex<SupportedServices, IGuideService> guideService)
IIndex<SupportedServices, IGuideService> guideService,
IRepoUpdater repoUpdater)
{
_lister = lister;
_guideService = guideService;
_repoUpdater = repoUpdater;
}
public override int Execute(CommandContext context, CliSettings settings)
public override async Task<int> ExecuteAsync(CommandContext context, CliSettings settings)
{
await _repoUpdater.UpdateRepo();
var guideService = _guideService[settings.Service];
_lister.ListQualities(guideService.GetQualities());
return 0;

@ -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<ListReleaseProfilesCommand.CliSettings>
internal class ListReleaseProfilesCommand : AsyncCommand<ListReleaseProfilesCommand.CliSettings>
{
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<ListReleaseProfilesCommand.C
public ListReleaseProfilesCommand(
ILogger log,
ISonarrGuideDataLister lister)
ISonarrGuideDataLister lister,
IRepoUpdater repoUpdater)
{
_log = log;
_lister = lister;
_repoUpdater = repoUpdater;
}
public override int Execute(CommandContext context, CliSettings settings)
public override async Task<int> 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.

@ -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<RadarrCommand.CliSettings>
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<RadarrCommand.CliSettings>
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<RadarrCommand.CliSettings>
{
_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<RadarrCommand.CliSettings>
return 0;
}
// Will throw if migration is required, otherwise just a warning is issued.
_migration.CheckNeededMigrations();
return (int) await _syncProcessor.ProcessConfigs(settings);
}
}

@ -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<SonarrCommand.CliSettings>
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<SonarrCommand.CliSettings>
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<SonarrCommand.CliSettings>
{
_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<SonarrCommand.CliSettings>
return 0;
}
// Will throw if migration is required, otherwise just a warning is issued.
_migration.CheckNeededMigrations();
return (int) await _syncProcessor.ProcessConfigs(settings);
}
}

@ -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<SyncCommand.CliSettings>
{
private readonly IMigrationExecutor _migration;
private readonly IRepoUpdater _repoUpdater;
private readonly ISyncProcessor _syncProcessor;
[UsedImplicitly]
@ -50,9 +52,11 @@ public class SyncCommand : AsyncCommand<SyncCommand.CliSettings>
public SyncCommand(
IMigrationExecutor migration,
IRepoUpdater repoUpdater,
ISyncProcessor syncProcessor)
{
_migration = migration;
_repoUpdater = repoUpdater;
_syncProcessor = syncProcessor;
}
@ -61,6 +65,7 @@ public class SyncCommand : AsyncCommand<SyncCommand.CliSettings>
{
// Will throw if migration is required, otherwise just a warning is issued.
_migration.CheckNeededMigrations();
await _repoUpdater.UpdateRepo();
return (int) await _syncProcessor.ProcessConfigs(settings);
}

Loading…
Cancel
Save