mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-07 13:08:14 +08:00
Implemented AddAsyncDelegate
(#766)
This commit is contained in:
@ -23,7 +23,7 @@ internal sealed class Configurator : IUnsafeConfigurator, IConfigurator, IConfig
|
||||
public void AddExample(params string[] args)
|
||||
{
|
||||
Examples.Add(args);
|
||||
}
|
||||
}
|
||||
|
||||
public ConfiguredCommand SetDefaultCommand<TDefaultCommand>()
|
||||
where TDefaultCommand : class, ICommand
|
||||
@ -42,6 +42,14 @@ internal sealed class Configurator : IUnsafeConfigurator, IConfigurator, IConfig
|
||||
|
||||
public ICommandConfigurator AddDelegate<TSettings>(string name, Func<CommandContext, TSettings, int> func)
|
||||
where TSettings : CommandSettings
|
||||
{
|
||||
var command = Commands.AddAndReturn(ConfiguredCommand.FromDelegate<TSettings>(
|
||||
name, (context, settings) => Task.FromResult(func(context, (TSettings)settings))));
|
||||
return new CommandConfigurator(command);
|
||||
}
|
||||
|
||||
public ICommandConfigurator AddAsyncDelegate<TSettings>(string name, Func<CommandContext, TSettings, Task<int>> func)
|
||||
where TSettings : CommandSettings
|
||||
{
|
||||
var command = Commands.AddAndReturn(ConfiguredCommand.FromDelegate<TSettings>(
|
||||
name, (context, settings) => func(context, (TSettings)settings)));
|
||||
|
Reference in New Issue
Block a user