CSharp · Console
// @nuget: CommandLineParser -Version 2.3.0
using System;
using CommandLine;
namespace Cmd
{
public class Program
{
public static void UseCase(int index, bool IgnoreUnknownArguments, string args)
{
Console.WriteLine("Case "+index);
var parser = new Parser(with =>
{
with.IgnoreUnknownArguments = IgnoreUnknownArguments;
with.HelpWriter = Console.Out;
});
var result = parser.ParseArguments<Options>(args.Split());
result.WithParsed<Options>(options => options.Dump());
result.WithNotParsed<Options>(errs => errs.Dump());
}
public static void Main()
{
UseCase(1, false, "-i 1 -j");
UseCase(2, true, "-i 1 -j");
UseCase(3, true, "-i 1 abc");
}
}
class Options {
[Option('i', HelpText = "an int")]
public int anInt { get; set; }
}
}