Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Spectre.Console.Cli/IConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -27,7 +29,8 @@ public void SetHelpProvider<T>()
/// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,25 @@ public Configurator(ITypeRegistrar registrar)
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>()
Expand Down
27 changes: 13 additions & 14 deletions src/Tests/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ public Task Should_Output_Default_Command_And_Additional_Commands_When_Default_C
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
Expand Down Expand Up @@ -539,10 +539,9 @@ public Task Should_Output_Custom_Help_When_Configured_By_Type()
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
Expand Down Expand Up @@ -952,12 +951,12 @@ public Task Should_Output_Examples_Defined_On_Root_If_Default_Command_Is_Specifi
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
Expand Down