using System.Collections.Generic;
using System.Threading.Tasks;
public static void Main()
private static readonly HeadingInfo HeadingInfo = new HeadingInfo("sampleapp", "1.8");
public static void Main1(string[] args)
var options = new Options();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);
CommandLine.Parser.Default.ParseArguments<Options>(args)
.WithParsed<Options> (o=> Run(o))
.WithNotParsed<Options> (errors=> HandleParseError(errors));
private static void Run(Options options)
if (options.VerboseLevel == null)
Console.WriteLine("verbose [off]");
options.VerboseLevel < 0 || options.VerboseLevel > 2 ? "#invalid value#" : options.VerboseLevel.ToString());
Console.WriteLine("input file: {0} ...", options.InputFile);
foreach (string defFile in options.DefinitionFiles)
Console.WriteLine(" using definition file: {0}", defFile);
Console.WriteLine(" start offset: {0}", options.StartOffset);
Console.WriteLine(" tabular data computation: {0}", options.Calculate.ToString().ToLowerInvariant());
Console.WriteLine(" on errors: {0}", options.IgnoreErrors ? "continue" : "stop processing");
Console.WriteLine(" optimize for: {0}", options.Optimization.ToString().ToLowerInvariant());
if (options.AllowedOperators != null)
var builder = new StringBuilder();
builder.Append(" allowed operators: ");
foreach (string op in options.AllowedOperators)
Console.WriteLine(builder.Remove(builder.Length - 2, 2).ToString());
if (!string.IsNullOrEmpty(options.OutputFile))
HeadingInfo.WriteMessage(string.Format("writing elaborated data: {0} ...", options.OutputFile));
HeadingInfo.WriteMessage("elaborated data:");
Console.WriteLine("[...]");
private static void HandleParseError(IEnumerable<Error> errors)
Console.WriteLine("HandleErrors");
public sealed class Options
[Option('r', "read", MetaValue = "FILE", Required = true, HelpText = "Input file with data to process.")]
public string InputFile {get; set;}
[Option('w', "write", MetaValue = "FILE", HelpText = "Output FILE with processed data (otherwise standard output).")]
public string OutputFile { get; set; }
[Option("calculate", HelpText = "Add results in bottom of tabular data.")]
public bool Calculate { get; set; }
[Option('v', MetaValue = "INT", HelpText = "Verbose level. Range: from 0 to 2.")]
public int? VerboseLevel { get; set; }
[Option('i', HelpText = "If file has errors don't stop processing.")]
public bool IgnoreErrors { get; set; }
[Option('j', "jump", MetaValue = "INT", Default = 0, HelpText = "Data processing start offset.")]
public double StartOffset { get; set; }
[Option("optimize", HelpText = "Optimize for Speed|Accuracy.")]
public OptimizeFor Optimization {get;set;}
public IEnumerable<string> DefinitionFiles { get; set; }
[Option('o', "operators", Separator = ';', HelpText = "Operators included in processing (+;-;...)." +
" Separate each operator with a semicolon." + " Do not include spaces between operators and separator.")]
public IEnumerable<string> AllowedOperators { get; set; }