If I have the following code:
using ConsoleAppFramework;
// Create a CancellationTokenSource that will be cancelled when 'Q' is pressed.
var cts = new CancellationTokenSource();
_ = Task.Run(() =>
{
while (Console.ReadKey().Key != ConsoleKey.Q) ;
Console.WriteLine();
cts.Cancel();
});
var app = ConsoleApp.Create();
app.Add<BasicCommands>();
await app.RunAsync(args, cts.Token);
public class BasicCommands
{
/// <summary>
/// Prints a hello world message and cites the command source.
/// </summary>
/// <returns>exit code</returns>
[Command("")]
public int Run(ConsoleAppContext context)
{
Console.WriteLine("Hello world! ({0})", context.CommandName);
return 0;
}
}
You get the error:
CS0051: Inconsistent accessibility: parameter type 'ConsoleAppContext' is less accessible than the method 'BasicCommands.Run(ConsoleAppContext)'
If you change the Run method to be internal, instead of public, then you get this error:
CAF012: ConsoleAppBuilder.Add<T> class must have at least one public method.
BUT, if you change await app.RunAsync(args, cts.Token) to become just app.Run(args);, AND you have the method declared as internal, then it all works fine.
This prevents you from having an asynchronous execution in Program.cs if you want to customize the doc comments of the root command in any way. Furthermore, the internal commands won't even get picked up by the ConsoleAppBuilder, so it seems the only way you can use the ConsoleAppBuilder is if you use the standard lambda-based Add method.
If I have the following code:
You get the error:
If you change the
Runmethod to beinternal, instead ofpublic, then you get this error:BUT, if you change
await app.RunAsync(args, cts.Token)to become justapp.Run(args);, AND you have the method declared asinternal, then it all works fine.This prevents you from having an asynchronous execution in
Program.csif you want to customize the doc comments of the root command in any way. Furthermore, theinternalcommands won't even get picked up by the ConsoleAppBuilder, so it seems the only way you can use theConsoleAppBuilderis if you use the standard lambda-basedAddmethod.