spectreconsole / spectre.console

A .NET library that makes it easier to create beautiful console applications.
https://spectreconsole.net
MIT License
9.43k stars 498 forks source link

Support multiple interceptors together #1405

Closed aa-dit-yuh closed 10 months ago

aa-dit-yuh commented 10 months ago

Is your feature request related to a problem? Please describe. Add support for invoking two or more interceptors.

Describe the solution you'd like Replace SetInterceptor on IConfigurator with AddInterceptor method that allows chaining of interceptors.

Describe alternatives you've considered Today, one can create the class ChainedInterceptor that delegates to multiple interceptors to circumvent this feature gap.

class ChainedInterceptor(params ICommandInterceptor[] interceptors) : ICommandInterceptor
{
    public void Intercept(CommandContext context, CommandSettings settings)
    {
        foreach (var interceptor in interceptors)
        {
            interceptor.Intercept(context, settings);
        }
    }
}

I'm interested in having library support for interceptor chaining.

Additional context

aa-dit-yuh commented 10 months ago

I'll be happy to contribute code to close this feature request. However, I'm not sure how to achieve this feature request without causing backward-incompatible changes to either the IConfigurator or the ICommandAppSettings interface.

patriksvensson commented 10 months ago

Wouldn't it be better if we allowed multiple interceptors to be registered instead of a single one?

aa-dit-yuh commented 10 months ago

Yes, that's the intention of the feature request too. The SetInterceptor method can be deprecated in favour of an AddInterceptor method on the IConfigurator interface IMO.

nils-a commented 10 months ago

@aditnryn would #1412 solve your problem?

FrankRay78 commented 10 months ago

Fixed by https://github.com/spectreconsole/spectre.console/pull/1412.