Skip to content

Instantly share code, notes, and snippets.

@Nihlus
Created July 9, 2020 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nihlus/de500153d35d623c217dabafe456aa86 to your computer and use it in GitHub Desktop.
Save Nihlus/de500153d35d623c217dabafe456aa86 to your computer and use it in GitHub Desktop.
// @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