Getting start: Named options

CSharp · Console

/Program.cs

// @nuget: CommandLineParser -Version 2.7.82
//Getting start: Named options

using System;
using System.Collections.Generic;
using CommandLine;

public class Program {
	public static void Main () {
		var args = "-t int:long:string".Split ();
		// (1) default options
		var result = Parser.Default.ParseArguments<Options> (args);
		// or (2) build and configure instance
		//var parser = new Parser(with => with.EnableDashDash = true);
		//var result = parser.ParseArguments<Options>(args);
		result.WithParsed (options => {
			Console.WriteLine("Types are: {0}", String.Join(", ", options.Types));
		})
			.WithNotParsed (errs => Console.WriteLine("Failed with errors:\n{0}",
			String.Join("\n",errs)));
	}
}

class Options {
	[Option]
	public string UserId { get; set; }

	[Option ('t', Separator = ':')]
	public IEnumerable<string> Types { get; set; }
}
;