You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/Recyclarr.Cli/Console/Commands/ConfigListCommand.cs

56 lines
1.7 KiB

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using Recyclarr.Cli.Console.Helpers;
using Recyclarr.TrashLib.Config.Listers;
using Recyclarr.TrashLib.ExceptionTypes;
using Recyclarr.TrashLib.Processors;
using Recyclarr.TrashLib.Repo;
using Spectre.Console.Cli;
namespace Recyclarr.Cli.Console.Commands;
[UsedImplicitly]
[Description("List configuration files in various ways.")]
public class ConfigListCommand : AsyncCommand<ConfigListCommand.CliSettings>
{
private readonly ILogger _log;
private readonly ConfigListProcessor _processor;
private readonly IRepoUpdater _repoUpdater;
[SuppressMessage("Design", "CA1034:Nested types should not be visible")]
public class CliSettings : BaseCommandSettings
{
[CommandArgument(0, "[ListCategory]")]
[EnumDescription<ConfigListCategory>("The type of configuration information to list.")]
public ConfigListCategory ListCategory { get; [UsedImplicitly] init; } = ConfigListCategory.Local;
}
public ConfigListCommand(ILogger log, ConfigListProcessor processor, IRepoUpdater repoUpdater)
{
_log = log;
_processor = processor;
_repoUpdater = repoUpdater;
}
public override async Task<int> ExecuteAsync(CommandContext context, CliSettings settings)
{
await _repoUpdater.UpdateRepo();
try
{
_processor.Process(settings.ListCategory);
}
catch (FileExistsException e)
{
_log.Error(
"The file {ConfigFile} already exists. Please choose another path or " +
"delete/move the existing file and run this command again", e.AttemptedPath);
return 1;
}
return 0;
}
}