A C# library to help build console applications (command line interface).
using System;
using CliHelper;
namespace PrintApp
{
public static class PrintAppMain
{
public static void Main(params string[] args)
{
var app = new CliApplication("PrintApp");
var runCommand = app.RegisterCommand("print",
"Print something in the console.", Run);
runCommand.RegisterParameter("message", "Write message.", 'm');
runCommand.RegisterFlag("error", "Print in red.", 'e');
}
private static void Run(ParameterWithValues[] parameters, Flag[] flags)
{
var error = flags.HasFlag("error");
if (error) {
Console.ForegroundColor = ConsoleColor.Red;
}
var message = parameters.GetParameterByName("message");
Console.WriteLine(message?.Values[0]);
Console.ForegroundColor = ConsoleColor.White;
}
}
}
After build, do something like:
./PrintApp print --message "Hello!"
# or
./PrintApp print -m "Error!" --error