using Refitter.Core; namespace Refitter; /// /// Writes planned files to disk and reports progress via . /// public class CliFileWriter : IFileWriter { private readonly IGenerationReporter _reporter; /// /// Initializes a new instance of the class. /// /// The generation reporter for progress reporting. public CliFileWriter(IGenerationReporter reporter) { _reporter = reporter ?? throw new ArgumentNullException(nameof(reporter)); } /// public async Task WriteAsync(PlannedFile file, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); var dir = Path.GetDirectoryName(file.Path); if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir)) Directory.CreateDirectory(dir); await File.WriteAllTextAsync(file.Path, file.Content, cancellationToken); _reporter.ReportFileWritten(file.Path); } }