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

Custom HelpProvider is being overridden by the default HelpProvider #1360

Closed kedde closed 12 months ago

kedde commented 12 months ago

Information

Describe the bug

Can not register a Custom HelpProvider when using Microsoft.Extensions.DependencyInjection & Spectre.Console.Cli.Extensions.DependencyInjection. The default HelpProvider is used in stead of the custom help provider.

My guess is, that the following line is overriding the HelpProvider.

https://github.com/spectreconsole/spectre.console/blob/131b37fff858f8d5dd483ff369bb3d43a07c1e08/src/Spectre.Console.Cli/Internal/CommandExecutor.cs#L27

To Reproduce Steps to reproduce the behavior.

I installed these two nuget packages:

and modified the test Should_Output_Custom_Help_When_Registered_By_Instance to use

[Fact]
[Expectation("Custom_Help_Registered_By_Instance")]
public Task Should_Output_Custom_Help_When_Registered_By_Instance()
{
    var services = new ServiceCollection();
    var registrar = new DependencyInjectionRegistrar(services);

    // Given
    var fixture = new CommandAppTester(registrar);
    fixture.Configure(configurator =>
    {
        // Create the custom help provider
        var helpProvider = new CustomHelpProvider(configurator.Settings, "1.0");

        // Register the custom help provider instance
        registrar.RegisterInstance(typeof(IHelpProvider), helpProvider);

        configurator.SetApplicationName("myapp");
        configurator.AddCommand<DogCommand>("dog");
    });

    // When
    var result = fixture.Run();

    // Then
    return Verifier.Verify(result.Output);
}

Expected behavior

Custom HelpProvider should be used.

Screenshots If applicable, add screenshots to help explain your problem. billede

Additional context Add any other context about the problem here.

nils-a commented 12 months ago

Closing as duplicate of #1313