CSharp · Console
//https://github.com/commandlineparser/commandline/issues/421
// @nuget: CommandLineParser -Version 2.5.0
using System;
using CommandLine;
public class Program
{
public static void Main()
{
var text="--with-some-feature";
Main1(text);
Console.WriteLine("---------");
text="--without-other-feature";
Main1(text);
}
static void Main1(string text)
{
Console.WriteLine("Command => {0}",text);
var p = new CommandLine.Parser();
//var text="--with-some-feature";
//var text="--without-other-feature";
var args = text.Split();
var result= p.ParseArguments<Options>(args)
.WithParsed(options =>{
Console.WriteLine("WithSomeFeature= {0}",options.WithSomeFeature );
Console.WriteLine("WithoutOtherFeature= {0}",options.WithoutOtherFeature );
})
.WithNotParsed (e=>e.Dump());
}
}
class Options
{
[Option("with-some-feature", SetName = "enable")]
public bool WithSomeFeature { get; set; }
[Option("without-other-feature", SetName = "disable")]
public bool WithoutOtherFeature { get; set; }
}