A Command Line Interface ParseR for .Net 3.5+ and .Net Core
Created by Dan Nemec
Here's a quick but powerful example of the objects this library enables you to build:
[ApplicationInfo(Description = "This is a set of options.")]
public class Options
{
[NamedArgument('v', "verbose", Action = ParseAction.Count,
Description = "Increase the verbosity of the output.")]
public int Verbosity { get; set; }
[PositionalArgument(0, MetaVar = "OUT",
Description = "Output file.")]
public string OutputFile { get; set; }
[PositionalArgument(1, MetaVar = "N",
NumArgs = 1,
Constraint = NumArgsConstraint.AtLeast,
Description = "Numbers to sum.")]
public List<int> Numbers { get; set; }
}
static void Main()
{
var opt = CliParser.Parse<Options>(
"-vvv output.txt 1 2 -1 7".Split());
Console.WriteLine(opt.Verbosity);
// >>> 3
Console.WriteLine(opt.OutputFile);
// >>> output.txt
var sum = 0;
foreach (var number in opt.Numbers)
{
sum += number;
}
Console.WriteLine(sum);
// >>> 9
}
You can explore additional documentation by selecting sections from the navigation bar at the top of the page.