spectre.console
spectre.console copied to clipboard
enhanced async support
few notes / enhancements that are recommended when handling async commands in a cli application.
When using async command in cli, it is recommended to add cancelation token to be passed to "ExecuteAsync" method console methods both in and out directions / write and read to have async version similar to: System.Console.Out.WriteLineAsync & System.Console.In.ReadLineAsync.
Thanks
Please upvote :+1: this issue if you are interested in it.
Related to/the same as: https://github.com/spectreconsole/spectre.console/issues/701, CLI Command RunAsync support passing in/propagating a CancelationToken
Can I have a go at this?
I gave it a shot here. Sorry if I was supposed to talk about my implementations as I was making the changes, this is my first github contribution and I don't really know the etiquette.
Essentially, I just added in a CancellationToken parameter for the command classes and the internal classes that call them. Only the abstract ExecuteAsync for the AsyncCommand has a CancellationToken parameter so that the users can handle the cancellation logic as shown in src/Tests/Spectre.Console.Cli.Tests/Data/Commands/AsynchronousCommand.cs.
The tests are essentially the same except they generate a CancellationTokenSource and the exception functions set the cts to cancel.
https://github.com/Call911plz/spectre.console/tree/AddCancellationToken
Closing as duplicate of #701. See also https://github.com/spectreconsole/spectre.console/pull/1904#issuecomment-3375870782