Changed IConfigurator to return IConfigurator instead of void for (#1762)

This commit is contained in:
Melvin Dommer 2025-02-24 14:57:23 -06:00 committed by GitHub
parent 11a320c7c9
commit 93668e92b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 20 deletions

View File

@ -9,13 +9,15 @@ public interface IConfigurator
/// Sets the help provider for the application.
/// </summary>
/// <param name="helpProvider">The help provider to use.</param>
public void SetHelpProvider(IHelpProvider helpProvider);
/// <returns>A configurator that can be used for further configuration.</returns>
public IConfigurator SetHelpProvider(IHelpProvider helpProvider);
/// <summary>
/// Sets the help provider for the application.
/// </summary>
/// <typeparam name="T">The type of the help provider to instantiate at runtime and use.</typeparam>
public void SetHelpProvider<T>()
/// <returns>A configurator that can be used for further configuration.</returns>
public IConfigurator SetHelpProvider<T>()
where T : IHelpProvider;
/// <summary>
@ -27,7 +29,8 @@ public interface IConfigurator
/// Adds an example of how to use the application.
/// </summary>
/// <param name="args">The example arguments.</param>
void AddExample(params string[] args);
/// <returns>A configurator that can be used for further configuration.</returns>
IConfigurator AddExample(params string[] args);
/// <summary>
/// Adds a command.

View File

@ -20,22 +20,25 @@ internal sealed class Configurator : IUnsafeConfigurator, IConfigurator, IConfig
Examples = new List<string[]>();
}
public void SetHelpProvider(IHelpProvider helpProvider)
public IConfigurator SetHelpProvider(IHelpProvider helpProvider)
{
// Register the help provider
_registrar.RegisterInstance(typeof(IHelpProvider), helpProvider);
return this;
}
public void SetHelpProvider<T>()
public IConfigurator SetHelpProvider<T>()
where T : IHelpProvider
{
// Register the help provider
_registrar.Register(typeof(IHelpProvider), typeof(T));
return this;
}
public void AddExample(params string[] args)
public IConfigurator AddExample(params string[] args)
{
Examples.Add(args);
return this;
}
public ConfiguredCommand SetDefaultCommand<TDefaultCommand>()

View File

@ -348,10 +348,10 @@ public sealed partial class CommandAppTests
fixture.SetDefaultCommand<LionCommand>();
fixture.Configure(configurator =>
{
configurator.SetApplicationName("myapp");
configurator.AddExample("20", "--alive");
configurator.AddCommand<GiraffeCommand>("giraffe");
configurator.SetHelpProvider(new RenderMarkupHelpProvider(configurator.Settings));
configurator.SetApplicationName("myapp")
.SetHelpProvider(new RenderMarkupHelpProvider(configurator.Settings))
.AddExample("20", "--alive")
.AddCommand<GiraffeCommand>("giraffe");
});
// When
@ -539,10 +539,9 @@ public sealed partial class CommandAppTests
fixture.Configure(configurator =>
{
// Configure the custom help provider type
configurator.SetHelpProvider<RedirectHelpProvider>();
configurator.SetApplicationName("myapp");
configurator.AddCommand<DogCommand>("dog");
configurator.SetHelpProvider<RedirectHelpProvider>()
.SetApplicationName("myapp")
.AddCommand<DogCommand>("dog");
});
// When
@ -952,12 +951,12 @@ public sealed partial class CommandAppTests
configurator.SetApplicationName("myapp");
// All root examples should be shown
configurator.AddExample("--name", "Rufus", "--age", "12", "--good-boy");
configurator.AddExample("--name", "Luna");
configurator.AddExample("--name", "Charlie");
configurator.AddExample("--name", "Bella");
configurator.AddExample("--name", "Daisy");
configurator.AddExample("--name", "Milo");
configurator.AddExample("--name", "Rufus", "--age", "12", "--good-boy")
.AddExample("--name", "Luna")
.AddExample("--name", "Charlie")
.AddExample("--name", "Bella")
.AddExample("--name", "Daisy")
.AddExample("--name", "Milo");
});
// When