static void Main(string[] args) { PublisherAppOptions options = PublisherAppOptions.GetPublisherAppOptionsFromArgs(args); Publisher pub; try { if (options.ShowHelp) { Console.WriteLine(PublisherAppOptions.GetUsage()); } if (!String.IsNullOrEmpty(options.ConfigPath) && File.Exists(options.ConfigPath)) { pub = new Publisher(options.ConfigPath); pub.ActionDone += PrintProgress; pub.Run(); } } catch (Exception e) { Console.WriteLine($"[FATAL ERROR]: {e.StackTrace}"); } }
/// <summary> /// Creates a PublisherAppOptions from the command line arguments /// </summary> /// <param name="args">Array of command line arguments</param> /// <returns>PublisherAppOptions with values from command line arguments</returns> public static PublisherAppOptions GetPublisherAppOptionsFromArgs(string[] args) { PublisherAppOptions options = new PublisherAppOptions(); if (args.Length == 0) { options.ShowHelp = true; } for (int i = 0; i != args.Length; ++i) { if (args[i].Equals(String.Empty)) { continue; } if (args[i].Equals("-help")) { options.ShowHelp = true; continue; } if ((args[i] == "-config-path") && (i + 1 <= (args.Length - 1))) { options.ConfigPath = args[++i]; continue; } } return(options); }