Skip to content

Commit 93668e9

Browse files
authored
Changed IConfigurator to return IConfigurator instead of void for (#1762)
1 parent 11a320c commit 93668e9

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

src/Spectre.Console.Cli/IConfigurator.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ public interface IConfigurator
99
/// Sets the help provider for the application.
1010
/// </summary>
1111
/// <param name="helpProvider">The help provider to use.</param>
12-
public void SetHelpProvider(IHelpProvider helpProvider);
12+
/// <returns>A configurator that can be used for further configuration.</returns>
13+
public IConfigurator SetHelpProvider(IHelpProvider helpProvider);
1314

1415
/// <summary>
1516
/// Sets the help provider for the application.
1617
/// </summary>
1718
/// <typeparam name="T">The type of the help provider to instantiate at runtime and use.</typeparam>
18-
public void SetHelpProvider<T>()
19+
/// <returns>A configurator that can be used for further configuration.</returns>
20+
public IConfigurator SetHelpProvider<T>()
1921
where T : IHelpProvider;
2022

2123
/// <summary>
@@ -27,7 +29,8 @@ public void SetHelpProvider<T>()
2729
/// Adds an example of how to use the application.
2830
/// </summary>
2931
/// <param name="args">The example arguments.</param>
30-
void AddExample(params string[] args);
32+
/// <returns>A configurator that can be used for further configuration.</returns>
33+
IConfigurator AddExample(params string[] args);
3134

3235
/// <summary>
3336
/// Adds a command.

src/Spectre.Console.Cli/Internal/Configuration/Configurator.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@ public Configurator(ITypeRegistrar registrar)
2020
Examples = new List<string[]>();
2121
}
2222

23-
public void SetHelpProvider(IHelpProvider helpProvider)
23+
public IConfigurator SetHelpProvider(IHelpProvider helpProvider)
2424
{
2525
// Register the help provider
2626
_registrar.RegisterInstance(typeof(IHelpProvider), helpProvider);
27+
return this;
2728
}
2829

29-
public void SetHelpProvider<T>()
30+
public IConfigurator SetHelpProvider<T>()
3031
where T : IHelpProvider
3132
{
3233
// Register the help provider
3334
_registrar.Register(typeof(IHelpProvider), typeof(T));
35+
return this;
3436
}
3537

36-
public void AddExample(params string[] args)
38+
public IConfigurator AddExample(params string[] args)
3739
{
3840
Examples.Add(args);
41+
return this;
3942
}
4043

4144
public ConfiguredCommand SetDefaultCommand<TDefaultCommand>()

src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs

+13-14
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ public Task Should_Output_Default_Command_And_Additional_Commands_When_Default_C
348348
fixture.SetDefaultCommand<LionCommand>();
349349
fixture.Configure(configurator =>
350350
{
351-
configurator.SetApplicationName("myapp");
352-
configurator.AddExample("20", "--alive");
353-
configurator.AddCommand<GiraffeCommand>("giraffe");
354-
configurator.SetHelpProvider(new RenderMarkupHelpProvider(configurator.Settings));
351+
configurator.SetApplicationName("myapp")
352+
.SetHelpProvider(new RenderMarkupHelpProvider(configurator.Settings))
353+
.AddExample("20", "--alive")
354+
.AddCommand<GiraffeCommand>("giraffe");
355355
});
356356

357357
// When
@@ -539,10 +539,9 @@ public Task Should_Output_Custom_Help_When_Configured_By_Type()
539539
fixture.Configure(configurator =>
540540
{
541541
// Configure the custom help provider type
542-
configurator.SetHelpProvider<RedirectHelpProvider>();
543-
544-
configurator.SetApplicationName("myapp");
545-
configurator.AddCommand<DogCommand>("dog");
542+
configurator.SetHelpProvider<RedirectHelpProvider>()
543+
.SetApplicationName("myapp")
544+
.AddCommand<DogCommand>("dog");
546545
});
547546

548547
// When
@@ -952,12 +951,12 @@ public Task Should_Output_Examples_Defined_On_Root_If_Default_Command_Is_Specifi
952951
configurator.SetApplicationName("myapp");
953952

954953
// All root examples should be shown
955-
configurator.AddExample("--name", "Rufus", "--age", "12", "--good-boy");
956-
configurator.AddExample("--name", "Luna");
957-
configurator.AddExample("--name", "Charlie");
958-
configurator.AddExample("--name", "Bella");
959-
configurator.AddExample("--name", "Daisy");
960-
configurator.AddExample("--name", "Milo");
954+
configurator.AddExample("--name", "Rufus", "--age", "12", "--good-boy")
955+
.AddExample("--name", "Luna")
956+
.AddExample("--name", "Charlie")
957+
.AddExample("--name", "Bella")
958+
.AddExample("--name", "Daisy")
959+
.AddExample("--name", "Milo");
961960
});
962961

963962
// When

0 commit comments

Comments
 (0)