Created
July 9, 2020 23:46
-
-
Save Nihlus/de500153d35d623c217dabafe456aa86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @nuget: CommandLineParser -Version 2.7.82 | |
using System; | |
using System.Collections.Generic; | |
using CommandLine; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var args = new string[] { "10 str1 str2 str3 1.1", "--otheroption", "doo" }; | |
// (1) default options | |
var result = Parser.Default.ParseArguments<Options>(args); | |
// or (2) build and configure instance | |
//var parser = new Parser(with => with.HelpWriter=Console.Out); | |
result.WithParsed(options => | |
{ | |
Console.WriteLine("Parser Success- Creating Options with values:"); | |
Console.WriteLine("options.Value= {0}", options.Value); | |
Console.WriteLine("options.OtherOption= {0}", options.OtherOption); | |
} | |
).WithNotParsed(errs => Console.WriteLine("Failed with errors:\n{0}", | |
String.Join("\n",errs))); | |
} | |
} | |
class Options | |
{ | |
[Value(1)] | |
public string Value | |
{ | |
get; | |
set; | |
} | |
[Option] | |
public string OtherOption | |
{ | |
get; | |
set; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment