Closed
Description
I'm using CommandLine library in embedded scenario where input and output are fully controlled by the host (and not associated with stdin and stdout). In this case, CancelOnProcessTermination
makes no sense. Instead, I want to propagate cancellation token from the host. At the moment, it is not possible. InvocationContext.GetCancellationToken
returning token associated with internal CTS. As a result, there is no way to cancel the operation by the host.
To address this issue, I would like to propose some changes in public API:
public static class ParserExtensions
{
// added token as the last parameter
public static int Invoke(this Parser parser, string commandLine, IConsole? console = null, CancellationToken token = default);
public static int Invoke(this Parser parser, string[] args, IConsole? console = null, CancellationToken token = default);
public static Task<int> InvokeAsync(this Parser parser, string commandLine, IConsole? console = null, CancellationToken token = default);
public static Task<int> InvokeAsync(this Parser parser, string[] args, IConsole? console = null, CancellationToken token = default);
}
public static class CommandExtensions
{
// added token as the last parameter
public static int Invoke(this Command command, string[] args, IConsole? console = null, CancellationToken token = default);
public static int Invoke(this Command command, string commandLine, IConsole? console = null, CancellationToken token = default);
public static Task<int> InvokeAsync(this Command command, string[] args, IConsole? console = null, CancellationToken token = default);
public static Task<int> InvokeAsync(this Command command, string commandLine, IConsole? console = null, CancellationToken token = default);
}
If the changes will be approved, I'm ready to make a PR.