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.
36 lines
1.1 KiB
36 lines
1.1 KiB
using System.IO.Abstractions;
|
|
using Recyclarr.Common.Extensions;
|
|
using Recyclarr.TrashGuide;
|
|
|
|
namespace Recyclarr.Config.Parsing.PostProcessing.ConfigMerging;
|
|
|
|
public class TemplateIncludeProcessor(IConfigTemplateGuideService templates) : IIncludeProcessor
|
|
{
|
|
public bool CanProcess(IYamlInclude includeDirective)
|
|
{
|
|
return includeDirective is TemplateYamlInclude;
|
|
}
|
|
|
|
public IFileInfo GetPathToConfig(IYamlInclude includeDirective, SupportedServices serviceType)
|
|
{
|
|
var include = (TemplateYamlInclude) includeDirective;
|
|
|
|
if (include.Template is null)
|
|
{
|
|
throw new YamlIncludeException("`template` property is required.");
|
|
}
|
|
|
|
var includePath = templates.GetIncludeData()
|
|
.Where(x => x.Service == serviceType)
|
|
.FirstOrDefault(x => x.Id.EqualsIgnoreCase(include.Template));
|
|
|
|
if (includePath is null)
|
|
{
|
|
throw new YamlIncludeException(
|
|
$"For service type '{serviceType}', unable to find config template with name '{include.Template}'");
|
|
}
|
|
|
|
return includePath.TemplateFile;
|
|
}
|
|
}
|