diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineManager.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineManager.cs index 8906496b83..9bef4479c5 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineManager.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineManager.cs @@ -39,7 +39,7 @@ internal async Task BuildAsync(string[] args, IPlatformOutpu await async.InitializeAsync(); } - commandLineOptionsProviders.Add(serviceInstance); + commandLineOptionsProviders.Add(new CommandLineOptionsProviderCache(serviceInstance)); } ICommandLineOptionsProvider[] systemCommandLineOptionsProviders = new[] diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsProviderCache.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsProviderCache.cs new file mode 100644 index 0000000000..2b7eac2e7e --- /dev/null +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsProviderCache.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.Testing.Platform.Extensions; +using Microsoft.Testing.Platform.Extensions.CommandLine; + +namespace Microsoft.Testing.Platform.CommandLine; + +internal struct CommandLineOptionsProviderCache(ICommandLineOptionsProvider commandLineOptionsProvider) : ICommandLineOptionsProvider +{ + private readonly ICommandLineOptionsProvider _commandLineOptionsProvider = commandLineOptionsProvider; + private CommandLineOption[]? _commandLineOptions; + + public readonly string Uid => _commandLineOptionsProvider.Uid; + + public readonly string Version => _commandLineOptionsProvider.Version; + + public readonly string DisplayName => _commandLineOptionsProvider.DisplayName; + + public readonly string Description => _commandLineOptionsProvider.Description; + + public IReadOnlyCollection GetCommandLineOptions() + { + _commandLineOptions ??= _commandLineOptionsProvider.GetCommandLineOptions().ToArray(); + + return _commandLineOptions; + } + + public readonly Task IsEnabledAsync() + => _commandLineOptionsProvider.IsEnabledAsync(); + + public readonly Task ValidateCommandLineOptionsAsync(ICommandLineOptions commandLineOptions) + => _commandLineOptionsProvider.ValidateCommandLineOptionsAsync(commandLineOptions); + + public readonly Task ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments) + => _commandLineOptionsProvider.ValidateOptionArgumentsAsync(commandOption, arguments); +}