NuGet: https://www.nuget.org/packages/CommandAppInterface/
This is a library for easy command interface making (actualy I used something like this in my other projects, but I tired of always typing if/else):
(you can see this example in CAIExamples folder)
First you need to use CAI namespace and create CAI instance:
AppInterface interface = new(caiName: "example", isCatchExceptions: true);
If you want to handle exceptions yourself, set isCatchExceptions false. Next to create a command, use AppInterface.AddCommand method:
interface.AddCommand(new Command("command_name", "this is a command without parameters", DoSomeDealMethod, "this is text about how to use this command);
interface.AddCommand<int>(new Command("command_with_int_parameter", "this command expects an int parameter after command name", MethodWithIntArgument, "usage: \"command_with_int_parameter 42\""));
Now commands support up to 4 various parameters. Each parameters implements IParsable.
In the command constructor, the command handler method is assigned. It must have the same number of parameters and the same types as those specified in the command generics
To start interface, run AppInterface.Start() method:
interface.Start();
The whole code looks like this:
...
AppInterface interface = new(caiName: "example", isCatchExceptions: true);
interface.AddCommand(new Command("command_name", "this is a command without parameters", DoSomeDealMethod, "this is text about how to use this command);
interface.AddCommand<int>(new Command("command_with_int_parameter", "this command expects an int parameter after command name", MethodWithIntArgument, "usage: \"command_with_int_parameter 42\""));
interface.Start();
...
Also CAI contains built-in commands:
You can run one CAI inside other. In this case when you type quit, you will exit from internal CAI and continue working in external CAI:
CAI uses Spectre.Console (Not Spectre.Console.Cli!!!), as stated in https://spectreconsole.net/best-practices, Spectre.Console supports Native AOT.