A simple, light-weight and strongly typed commandline parser made in .NET Standard!
PM> Install-Package MatthiWare.CommandLineParser
Example of configuring the port option using the Fluent API.
static void Main(string[] args)
{
// create the parser
var parser = new CommandLineParser<ServerOptions>();
// configure the options using the Fluent API
parser.Configure(options => options.Port)
.Name("p", "port")
.Description("The port of the server")
.Required();
// parse
var parserResult = parser.Parse(args);
// check for parsing errors
if (parserResult.HasErrors)
{
Console.ReadKey();
return -1;
}
var serverOptions = parserResult.Result;
Console.WriteLine($"Parsed port is {serverOptions.Port}");
}
private class ServerOptions
{
// options
public int Port { get; set; }
}
Run command line
dotnet myapp --port 2551