mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00
This commit is contained in:
parent
fc0b553a4a
commit
eb38f76a6a
@ -324,11 +324,16 @@ public static class ConfiguratorExtensions
|
|||||||
/// <param name="func">The delegate to execute as part of command execution.</param>
|
/// <param name="func">The delegate to execute as part of command execution.</param>
|
||||||
/// <returns>A command configurator that can be used to configure the command further.</returns>
|
/// <returns>A command configurator that can be used to configure the command further.</returns>
|
||||||
public static ICommandConfigurator AddDelegate<TSettings>(
|
public static ICommandConfigurator AddDelegate<TSettings>(
|
||||||
this IConfigurator<TSettings> configurator,
|
this IConfigurator<TSettings>? configurator,
|
||||||
string name,
|
string name,
|
||||||
Func<CommandContext, int> func)
|
Func<CommandContext, int> func)
|
||||||
where TSettings : CommandSettings
|
where TSettings : CommandSettings
|
||||||
{
|
{
|
||||||
|
if (typeof(TSettings).IsAbstract)
|
||||||
|
{
|
||||||
|
AddDelegate(configurator as IConfigurator<EmptyCommandSettings>, name, func);
|
||||||
|
}
|
||||||
|
|
||||||
if (configurator == null)
|
if (configurator == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(configurator));
|
throw new ArgumentNullException(nameof(configurator));
|
||||||
|
@ -1136,6 +1136,55 @@ public sealed partial class CommandAppTests
|
|||||||
data.ShouldBe(2);
|
data.ShouldBe(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Execute_Nested_Delegate_Empty_Command()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var app = new CommandAppTester();
|
||||||
|
app.Configure(cfg =>
|
||||||
|
{
|
||||||
|
cfg.AddBranch("a", d =>
|
||||||
|
{
|
||||||
|
d.AddDelegate("b", _ =>
|
||||||
|
{
|
||||||
|
AnsiConsole.MarkupLine("[red]Complete[/]");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// When
|
||||||
|
var result = app.Run([
|
||||||
|
"a", "b"
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.ExitCode.ShouldBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Execute_Delegate_Empty_Command_At_Root_Level()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var app = new CommandAppTester();
|
||||||
|
app.Configure(cfg =>
|
||||||
|
{
|
||||||
|
cfg.AddDelegate("a", _ =>
|
||||||
|
{
|
||||||
|
AnsiConsole.MarkupLine("[red]Complete[/]");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// When
|
||||||
|
var result = app.Run([
|
||||||
|
"a"
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.ExitCode.ShouldBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Should_Execute_Async_Delegate_Command_At_Root_Level()
|
public async void Should_Execute_Async_Delegate_Command_At_Root_Level()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user