diff --git a/src/Doki.CommandLine/JsonOutputOptionsProvider.cs b/src/Doki.CommandLine/JsonOutputOptionsProvider.cs index c957d09..b02173e 100644 --- a/src/Doki.CommandLine/JsonOutputOptionsProvider.cs +++ b/src/Doki.CommandLine/JsonOutputOptionsProvider.cs @@ -6,14 +6,25 @@ namespace Doki.CommandLine; internal class JsonOutputOptionsProvider : IOutputOptionsProvider { - public TOptions RequireOptions(string outputType) where TOutput : class, IOutput + private static readonly JsonSerializerOptions JsonSerializerOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + private readonly Dictionary _options = new(); + + public TOptions? GetOptions(string outputType) where TOutput : class, IOutput where TOptions : class, IOutputOptions { - throw new NotImplementedException(); + ArgumentNullException.ThrowIfNull(outputType); + + return _options.TryGetValue(outputType, out var options) + ? options?.Deserialize(JsonSerializerOptions) + : null; } public void AddOptions(string outputType, JsonElement? options) { - throw new NotImplementedException(); + _options[outputType] = options; } } \ No newline at end of file diff --git a/src/Doki.Output.Extensions/IOutputOptionsProvider.cs b/src/Doki.Output.Extensions/IOutputOptionsProvider.cs index 45c6869..25688af 100644 --- a/src/Doki.Output.Extensions/IOutputOptionsProvider.cs +++ b/src/Doki.Output.Extensions/IOutputOptionsProvider.cs @@ -2,6 +2,6 @@ public interface IOutputOptionsProvider { - TOptions RequireOptions(string outputType) where TOutput : class, IOutput + TOptions? GetOptions(string outputType) where TOutput : class, IOutput where TOptions : class, IOutputOptions; } \ No newline at end of file diff --git a/src/Doki.Output.Extensions/OutputExtensions.cs b/src/Doki.Output.Extensions/OutputExtensions.cs index d848755..a7380b2 100644 --- a/src/Doki.Output.Extensions/OutputExtensions.cs +++ b/src/Doki.Output.Extensions/OutputExtensions.cs @@ -19,9 +19,9 @@ public static IServiceCollection AddOutputOptions(this IServi services.AddSingleton>(provider => { var optionsProvider = provider.GetService(); - if (optionsProvider != null) return optionsProvider.RequireOptions(outputType); + var options = optionsProvider?.GetOptions(outputType); - return ActivatorUtilities.CreateInstance(provider); + return options ?? ActivatorUtilities.CreateInstance(provider); }); return services;