Files
spectre.console/src/Spectre.Console.Testing/Cli/CallbackCommandInterceptor.cs
Patrik Svensson 52c1d9122b Add global usings (#668)
* Use global usings

* Fix namespace declarations for test projects
2021-12-23 16:50:31 +01:00

24 lines
841 B
C#

namespace Spectre.Console.Testing;
/// <summary>
/// A <see cref="ICommandInterceptor"/> that triggers a callback when invoked.
/// </summary>
public sealed class CallbackCommandInterceptor : ICommandInterceptor
{
private readonly Action<CommandContext, CommandSettings> _callback;
/// <summary>
/// Initializes a new instance of the <see cref="CallbackCommandInterceptor"/> class.
/// </summary>
/// <param name="callback">The callback to call when the interceptor is invoked.</param>
public CallbackCommandInterceptor(Action<CommandContext, CommandSettings> callback)
{
_callback = callback ?? throw new ArgumentNullException(nameof(callback));
}
/// <inheritdoc/>
public void Intercept(CommandContext context, CommandSettings settings)
{
_callback(context, settings);
}
}