Implemented AddAsyncDelegate (#766)

This commit is contained in:
Ignacio Calvo
2023-05-25 12:31:01 +02:00
committed by GitHub
parent 0ec70a44db
commit 35ce60b596
13 changed files with 859 additions and 675 deletions

View File

@ -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; }
}
}

View File

@ -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);
}
}

View File

@ -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