Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Async Methods on CommandLineApplication that accept CancellationToken #153

Closed
bloudraak opened this issue Sep 17, 2018 · 4 comments
Closed
Assignees
Labels
enhancement help wanted We would be willing to take a well-written PR to help fix this.
Milestone

Comments

@bloudraak
Copy link

Describe the bug
Consider the following code snippet:

public async Task<int> ExecuteAsync<TCommand>(string[] args, CancellationToken cancellationToken = default) where TCommand:class
{
    cancellationToken.ThrowIfCancellationRequested();
    
    var app = new CommandLineApplication<TCommand>();
    try
    {
        app.Conventions
            .UseDefaultConventions()
            .UseConstructorInjection(Services);

        return app.Execute(args);
        
    }
    catch (CommandParsingException e)
    {
        await app.Out.WriteLineAsync(e.Message);
        app.ShowHelp();
        return -1;
    }
}

The API doesn't expose ExecuteAsync(args, cancellationToken).

To Reproduce
There is no ExecuteAsync method that takes a cancellation token, which in turn complicates matters when TCommand implements an ExecuteAsync method, which uses a cancellation token.

Expected behavior
The expectation is that all methods on CommandLineApplication exposes async methods that accepts a cancellation token, so that a long running application can be cancelled.

Additional context
The need exists to signal to the instance of TCommand that is running asynchronously that processing should be cancelled for whatever reason, e.g. the user pressed CTRL+C.

@bloudraak
Copy link
Author

In addition, async methods don't support passing in a cancellation token.

@natemcmaster natemcmaster changed the title Missing Async Methods on CommandLineApplication Add Async Methods on CommandLineApplication that accept CancellationToken Sep 25, 2018
@natemcmaster
Copy link
Owner

Somewhat related: #111. This is new API I would consider adding in 3.0 which I plan to start work on later this year.

@natemcmaster natemcmaster added this to the 3.0.0 milestone Sep 25, 2018
@natemcmaster natemcmaster added the help wanted We would be willing to take a well-written PR to help fix this. label Jan 6, 2019
@natemcmaster natemcmaster removed this from the 3.0.0 milestone Jan 6, 2019
@stale
Copy link

stale bot commented Apr 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 7 days.

@stale stale bot added the closed-wontfix This issue is closed because there are no plans to fix this. label Apr 6, 2019
@stale stale bot closed this as completed Apr 13, 2019
@natemcmaster natemcmaster added closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. and removed closed-wontfix This issue is closed because there are no plans to fix this. labels May 17, 2019
@natemcmaster
Copy link
Owner

Stale bot closed this, but I'm interested in adding this in 3.0. Reopening.

@natemcmaster natemcmaster reopened this Jul 16, 2019
@stale stale bot removed the closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. label Jul 16, 2019
@natemcmaster natemcmaster added this to the 3.0 milestone Jul 16, 2019
@natemcmaster natemcmaster modified the milestones: 3.0, 2.4.0-beta Jul 24, 2019
@natemcmaster natemcmaster self-assigned this Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted We would be willing to take a well-written PR to help fix this.
Projects
None yet
Development

No branches or pull requests

2 participants