CSharp · Console
// @nuget: CommandLineParser -Version 1.9.71
using System;
using CommandLine;
public class Program
{
public static void Main(string[] args)
{
UseCase("Case: different sets- allowed","--enablejavascript --anonymouslogin"); //different sets
UseCase("same set- Not Allowed","--enablejavascript --documentroot"); //same set
}
public static void UseCase(string title, string argCommand)
{
Console.WriteLine("------" + title + "------");
var args= argCommand.Split();
//args.Dump();
var options = new OptionsWithDefaultSet();
bool isOk = new Parser(s =>
{
s.MutuallyExclusive = true;
}).ParseArguments(args, options);
if (isOk)
{
options.Dump();
}
else
{
Console.WriteLine("Not parsed");
}
}
}
class OptionsWithDefaultSet
{
[Option(MutuallyExclusiveSet = "web")]
public string DocumentRoot { get; set; }
[Option(MutuallyExclusiveSet = "web")]
public bool EnableJavaScript { get; set; }
[Option(MutuallyExclusiveSet = "ftp")]
public string FtpDirectory { get; set; }
[Option(MutuallyExclusiveSet = "ftp")]
public bool AnonymousLogin { get; set; }
}