mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-16 12:13:22 +08:00
Changed IConfigurator to return IConfigurator instead of void for (#1762)
This commit is contained in:
parent
11a320c7c9
commit
93668e92b6
@ -9,13 +9,15 @@ public interface IConfigurator
|
|||||||
/// Sets the help provider for the application.
|
/// Sets the help provider for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="helpProvider">The help provider to use.</param>
|
/// <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>
|
/// <summary>
|
||||||
/// Sets the help provider for the application.
|
/// Sets the help provider for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type of the help provider to instantiate at runtime and use.</typeparam>
|
/// <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;
|
where T : IHelpProvider;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -27,7 +29,8 @@ public interface IConfigurator
|
|||||||
/// Adds an example of how to use the application.
|
/// Adds an example of how to use the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="args">The example arguments.</param>
|
/// <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>
|
/// <summary>
|
||||||
/// Adds a command.
|
/// Adds a command.
|
||||||
|
@ -20,22 +20,25 @@ internal sealed class Configurator : IUnsafeConfigurator, IConfigurator, IConfig
|
|||||||
Examples = new List<string[]>();
|
Examples = new List<string[]>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetHelpProvider(IHelpProvider helpProvider)
|
public IConfigurator SetHelpProvider(IHelpProvider helpProvider)
|
||||||
{
|
{
|
||||||
// Register the help provider
|
// Register the help provider
|
||||||
_registrar.RegisterInstance(typeof(IHelpProvider), helpProvider);
|
_registrar.RegisterInstance(typeof(IHelpProvider), helpProvider);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetHelpProvider<T>()
|
public IConfigurator SetHelpProvider<T>()
|
||||||
where T : IHelpProvider
|
where T : IHelpProvider
|
||||||
{
|
{
|
||||||
// Register the help provider
|
// Register the help provider
|
||||||
_registrar.Register(typeof(IHelpProvider), typeof(T));
|
_registrar.Register(typeof(IHelpProvider), typeof(T));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddExample(params string[] args)
|
public IConfigurator AddExample(params string[] args)
|
||||||
{
|
{
|
||||||
Examples.Add(args);
|
Examples.Add(args);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredCommand SetDefaultCommand<TDefaultCommand>()
|
public ConfiguredCommand SetDefaultCommand<TDefaultCommand>()
|
||||||
|
@ -348,10 +348,10 @@ public sealed partial class CommandAppTests
|
|||||||
fixture.SetDefaultCommand<LionCommand>();
|
fixture.SetDefaultCommand<LionCommand>();
|
||||||
fixture.Configure(configurator =>
|
fixture.Configure(configurator =>
|
||||||
{
|
{
|
||||||
configurator.SetApplicationName("myapp");
|
configurator.SetApplicationName("myapp")
|
||||||
configurator.AddExample("20", "--alive");
|
.SetHelpProvider(new RenderMarkupHelpProvider(configurator.Settings))
|
||||||
configurator.AddCommand<GiraffeCommand>("giraffe");
|
.AddExample("20", "--alive")
|
||||||
configurator.SetHelpProvider(new RenderMarkupHelpProvider(configurator.Settings));
|
.AddCommand<GiraffeCommand>("giraffe");
|
||||||
});
|
});
|
||||||
|
|
||||||
// When
|
// When
|
||||||
@ -539,10 +539,9 @@ public sealed partial class CommandAppTests
|
|||||||
fixture.Configure(configurator =>
|
fixture.Configure(configurator =>
|
||||||
{
|
{
|
||||||
// Configure the custom help provider type
|
// Configure the custom help provider type
|
||||||
configurator.SetHelpProvider<RedirectHelpProvider>();
|
configurator.SetHelpProvider<RedirectHelpProvider>()
|
||||||
|
.SetApplicationName("myapp")
|
||||||
configurator.SetApplicationName("myapp");
|
.AddCommand<DogCommand>("dog");
|
||||||
configurator.AddCommand<DogCommand>("dog");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// When
|
// When
|
||||||
@ -952,12 +951,12 @@ public sealed partial class CommandAppTests
|
|||||||
configurator.SetApplicationName("myapp");
|
configurator.SetApplicationName("myapp");
|
||||||
|
|
||||||
// All root examples should be shown
|
// All root examples should be shown
|
||||||
configurator.AddExample("--name", "Rufus", "--age", "12", "--good-boy");
|
configurator.AddExample("--name", "Rufus", "--age", "12", "--good-boy")
|
||||||
configurator.AddExample("--name", "Luna");
|
.AddExample("--name", "Luna")
|
||||||
configurator.AddExample("--name", "Charlie");
|
.AddExample("--name", "Charlie")
|
||||||
configurator.AddExample("--name", "Bella");
|
.AddExample("--name", "Bella")
|
||||||
configurator.AddExample("--name", "Daisy");
|
.AddExample("--name", "Daisy")
|
||||||
configurator.AddExample("--name", "Milo");
|
.AddExample("--name", "Milo");
|
||||||
});
|
});
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
Loading…
x
Reference in New Issue
Block a user