mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Implemented AddAsyncDelegate
(#766)
This commit is contained in:
@ -9,7 +9,7 @@ public static partial class Program
|
||||
{
|
||||
[CommandOption("--count")]
|
||||
[Description("The number of bars to print")]
|
||||
[DefaultValue(1)]
|
||||
[DefaultValue(3)]
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
@ -14,7 +15,13 @@ public static partial class Program
|
||||
.WithDescription("Foos the bars");
|
||||
|
||||
config.AddDelegate<BarSettings>("bar", Bar)
|
||||
.WithDescription("Bars the foos"); ;
|
||||
.WithDescription("Bars the foos");
|
||||
|
||||
config.AddAsyncDelegate("fooAsync", FooAsync)
|
||||
.WithDescription("Foos the bars asynchronously");
|
||||
|
||||
config.AddAsyncDelegate<BarSettings>("barAsync", BarAsync)
|
||||
.WithDescription("Bars the foos asynchronously");
|
||||
});
|
||||
|
||||
return app.Run(args);
|
||||
@ -35,4 +42,20 @@ public static partial class Program
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static Task<int> FooAsync(CommandContext context)
|
||||
{
|
||||
AnsiConsole.WriteLine("Foo");
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
private static Task<int> BarAsync(CommandContext context, BarSettings settings)
|
||||
{
|
||||
for (var index = 0; index < settings.Count; index++)
|
||||
{
|
||||
AnsiConsole.WriteLine("Bar");
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console.Json\Spectre.Console.Json.csproj" />
|
||||
<ProjectReference Include="..\..\Shared\Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user