using System.Collections.Generic;
static ParserResult<Options> parserResult;
public static void Main()
string[] args = new[]{"--stdin", "123"};
Console.WriteLine("Call help screen when Parser success");
var parser = new CommandLine.Parser(with => with.HelpWriter = null);
parserResult = Parser.Default.ParseArguments<Options>(args);
parserResult.WithParsed(Run).WithNotParsed(errs => HandleErrors(errs));
static void HandleErrors(IEnumerable<Error> errs)
Console.WriteLine("Parser Fail");
private static void Run(Options options)
Console.WriteLine("parser SUCCESS");
Console.WriteLine("Validation fail");
var helpText = GetHelp<Options>(parserResult);
Console.WriteLine(helpText);
static string GetHelp<T>(ParserResult<T> result)
return HelpText.AutoBuild(result, h => h, e => e);
static bool validate(Options options)
if (options.FileName == null)
[Option(Default = false, HelpText = "Prints all messages to standard output.")]
[Option("stdin", Default = false, HelpText = "Read from stdin")]
[Option("file", HelpText = "File name")]
[Value(0, MetaName = "offset", HelpText = "File offset.")]