private static void Initialize(string[] args) { string invokedVerb = null; object invokedVerbInstance = null; var opts = new CmdArgs(); if (args.Length == 0 || CommandLine.Parser.Default.ParseArguments( args, opts, (verb, subOptions) => { // if parsing succeeds the verb name and correct instance // will be passed to onVerbCommand delegate (string,object) invokedVerb = verb; invokedVerbInstance = subOptions; })) { if (invokedVerbInstance is CmdArgs.BatchSubOptions) { } else { App.Main(); } } else { AppConsole.Show(); Console.WriteLine(opts.GetUsage(invokedVerb)); AppConsole.Hide(); } }
/// <summary> /// Initializes a new instance of the application class /// </summary> static CmdArgs() { var opts = new CmdArgs(); var tmpArgs = Environment.GetCommandLineArgs().ToList(); if (tmpArgs.Any()) { tmpArgs.RemoveAt(0); CommandLine.Parser.Default.ParseArguments( tmpArgs.ToArray(), opts, (verb, subOptions) => { // if parsing succeeds the verb name and correct instance // will be passed to onVerbCommand delegate (string,object) CommandLineArgs = subOptions as ICmdArgs; }); } }