using System.Collections.Generic;
public static void Main()
foreach(var args in new List<string[]> {
,new string[] { "AssemblyInfo.cs", "myproject.csproj" }
,new string[] { "-a", "App_Data/cachefile.json" }
,new string[] { "-m", "App_Data/cachefile.json", "App_Data/cachefile2.json" }
Console.WriteLine("*** RUN #{0}, args: {1}",runcount++,String.Join(" ",args));
public static void __YourMain(string[] args)
var parserResult = CommandLine.Parser.Default
.ParseArguments<TouchOptions>(args)
.WithParsed((TouchOptions opts) => { RunCommand(opts); })
.WithNotParsed((errs) => { errs.Dump(); });
static int RunCommand(TouchOptions TouchOptions)
Console.WriteLine("only change access time: {0}", IfTrue(TouchOptions.OnlyAccessTime));
Console.WriteLine("only change modification time: {0}", IfTrue(TouchOptions.OnlyModificationTime));
Console.WriteLine("do not create any files: {0}", IfTrue(TouchOptions.DontCreate));
Console.WriteLine("files:");
Console.WriteLine("=>" + String.Join(",", TouchOptions.Filenames.Select(_=>"\""+_+"\"")));
static string IfTrue(bool value) { if(value) return value.ToString(); else return "--"; }
public class TouchOptions
public IEnumerable<string> Filenames { get; set; }
[Option('c',"no-create",HelpText="")]
public bool DontCreate { get; set; }
[Option('a',HelpText="change only the access time")]
public bool OnlyAccessTime { get; set; }
[Option('m',HelpText="")]
public bool OnlyModificationTime { get; set; }