-
-
Notifications
You must be signed in to change notification settings - Fork 520
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
AddDelegateAsync or pass original arguments #766
Comments
I can prepare PR with the solution, but first I need to know which solution do you prefer. |
I think that adding an async delegate is more generic. I came here because I need that as a way to constructing an async command by myself (fiddling with the typeregistrar to build it your way is much more complicated). I would say, though, that ending the method name with |
Hello @WojciechNagorski, I'm going to merge @icalvo's linked PR shortly which will provide you with solution 2. However, I thought you might be interested to see the following example which passes data to an executing command through the CommandContext: using Spectre.Console;
using Spectre.Console.Cli;
public class Program
{
public static async Task Main(string[] args)
{
var app = new CommandApp();
app.SetDefaultCommand<AsynchronousCommand>()
.WithData(new string[] { "a", "b" });
app.Configure(config =>
{
config.PropagateExceptions();
});
await app.RunAsync(args);
}
}
public sealed class AsynchronousCommand : AsyncCommand
{
private readonly IAnsiConsole _console;
public AsynchronousCommand(IAnsiConsole console)
{
_console = console;
}
public async override Task<int> ExecuteAsync(CommandContext context)
{
_console.WriteLine($"AsynchronousCommand.ExecuteAsync");
_console.WriteLine($"- context.Data: {string.Join(", ", ((string[])context.Data))}");
return 0;
}
} |
Is your feature request related to a problem? Please describe.
I would like to run ASP Core application in one of the command:
But in this way, I'm not able to pass original args to my host:
So I tried use the
AddDelegate
method instead ofAddCommand
, but this method can't be async.Describe the solution you'd like
This problem can be solved in two ways:
AddDelegateAsync
:The text was updated successfully, but these errors were encountered: