A helper library for console command processing applications. This library provides the following functionality:
- All asynchronous API.
- Main program loop for command and command parameter entry and execution.
- Built in command for command and command parameter help.
- Automatic command state validation.
- Automatic command parameter value validation.
static void Main(string[] args)
{
var manager = new CommandManager();
manager.AddCommand("speak", new Command
{
Description = "Outputs the phrase parameter to the console window.",
Execute = command =>
{
Console.WriteLine($"{command.GetParameter("phrase").Value}");
return Task.FromResult(0);
}
}).AddParameter("phrase", new Parameter
{
Prompt = "Phrase",
Description = "The phrase to output to the console window.",
CantValidateMessage = "Phrase cannot be null or whitespace.",
Validate = value => Task.FromResult(!String.IsNullOrWhiteSpace(value))
});
Task.Run(async () => await manager.RunAsync()).Wait();
}
For a slightly more involved sample, refer to the ConsoleCommandProcessor.Sample project.