Skip to content

hyprsoftcorp/ConsoleCommandProcessor

Repository files navigation

Console Command Processor

A helper library for console command processing applications. This library provides the following functionality:

  1. All asynchronous API.
  2. Main program loop for command and command parameter entry and execution.
  3. Built in command for command and command parameter help.
  4. Automatic command state validation.
  5. Automatic command parameter value validation.

Hello World Code Sample

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.

Hello World Screenshot

alt text

About

A helper library for console command processing applications.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published