Skip to content

Commit

Permalink
introduce OutputOptions record instead of interface
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed May 5, 2024
1 parent 3c519aa commit f29f4fd
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Doki.CommandLine/Json/JsonOutputOptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class JsonOutputOptionsProvider(FileSystemInfo workingDirectory) : IOut
};

public TOptions? GetOptions<TOutput, TOptions>(string outputType) where TOutput : class, IOutput
where TOptions : class, IOutputOptions<TOutput>
where TOptions : OutputOptions<TOutput>
{
ArgumentNullException.ThrowIfNull(outputType);

Expand Down
7 changes: 0 additions & 7 deletions src/Doki.Output.Abstractions/IOutputOptions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace Doki.Output;

/// <summary>
/// Default output options.
/// </summary>
public sealed record DefaultOutputOptions<T> : IOutputOptions<T> where T : IOutput
// ReSharper disable once UnusedTypeParameter
public record OutputOptions<T> where T : IOutput
{
[JsonPropertyName("outputPath")] public DirectoryInfo OutputDirectory { get; init; } = null!;
}
2 changes: 1 addition & 1 deletion src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Doki.Output.ClassLibrary;

internal class ClassLibraryOutput(IOutputOptions<ClassLibraryOutput> options) : IOutput
public sealed class ClassLibraryOutput(ClassLibraryOutputOptions options) : IOutput

Check warning on line 3 in src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs

View workflow job for this annotation

GitHub Actions / Test

Parameter 'options' is unread.

Check warning on line 3 in src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs

View workflow job for this annotation

GitHub Actions / Test

Parameter 'options' is unread.

Check warning on line 3 in src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs

View workflow job for this annotation

GitHub Actions / Test

Parameter 'options' is unread.
{
public async Task WriteAsync(ContentList contentList, CancellationToken cancellationToken = default)

Check warning on line 5 in src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs

View workflow job for this annotation

GitHub Actions / Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 5 in src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs

View workflow job for this annotation

GitHub Actions / Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 5 in src/Doki.Output.ClassLibrary/ClassLibraryOutput.cs

View workflow job for this annotation

GitHub Actions / Test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Expand Down
4 changes: 1 addition & 3 deletions src/Doki.Output.ClassLibrary/ClassLibraryOutputOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Doki.Output.ClassLibrary;

public sealed record ClassLibraryOutputOptions : IOutputOptions<ClassLibraryOutput>
public sealed record ClassLibraryOutputOptions : OutputOptions<ClassLibraryOutput>
{
[JsonPropertyName("namespace")] public string Namespace { get; init; } = "Doki.Content";

Expand All @@ -11,6 +11,4 @@ public sealed record ClassLibraryOutputOptions : IOutputOptions<ClassLibraryOutp
[JsonPropertyName("targetFramework")] public string TargetFramework { get; init; } = "net8.0";

[JsonPropertyName("targetFrameworks")] public string[]? TargetFrameworks { get; init; }

[JsonPropertyName("outputPath")] public DirectoryInfo OutputDirectory { get; init; } = null!;
}
2 changes: 1 addition & 1 deletion src/Doki.Output.Extensions/IOutputOptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public interface IOutputOptionsProvider
{
TOptions? GetOptions<TOutput, TOptions>(string outputType) where TOutput : class, IOutput
where TOptions : class, IOutputOptions<TOutput>;
where TOptions : OutputOptions<TOutput>;
}
6 changes: 3 additions & 3 deletions src/Doki.Output.Extensions/OutputExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ public static class OutputExtensions
public static IServiceCollection AddOutputOptions<TOutput>(this IServiceCollection services, string outputType)
where TOutput : class, IOutput
{
return services.AddOutputOptions<TOutput, DefaultOutputOptions<TOutput>>(outputType);
return services.AddOutputOptions<TOutput, OutputOptions<TOutput>>(outputType);
}

public static IServiceCollection AddOutputOptions<TOutput, TOptions>(this IServiceCollection services,
string outputType) where TOutput : class, IOutput where TOptions : class, IOutputOptions<TOutput>
string outputType) where TOutput : class, IOutput where TOptions : OutputOptions<TOutput>
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(outputType);

services.AddSingleton<IOutputOptions<TOutput>>(provider =>
services.AddSingleton<OutputOptions<TOutput>>(provider =>
{
var optionsProvider = provider.GetService<IOutputOptionsProvider>();
var options = optionsProvider?.GetOptions<TOutput, TOptions>(outputType);
Expand Down
2 changes: 1 addition & 1 deletion src/Doki.Output.Markdown/MarkdownOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Doki.Output.Markdown;

internal class MarkdownOutput(IOutputOptions<MarkdownOutput> options) : IOutput
public sealed class MarkdownOutput(OutputOptions<MarkdownOutput> options) : IOutput
{
public async Task WriteAsync(ContentList contentList, CancellationToken cancellationToken = default)
{
Expand Down

0 comments on commit f29f4fd

Please sign in to comment.