public void Parse(IEnumerable <string> args, int id) { var src = new ArgumentCollection(args, '/', true); Assert.That(src.GetTimeout(), Is.EqualTo(300)); Assert.That(src.GetRetryCount(), Is.EqualTo(10)); Assert.That(src.GetCommand(), Is.Not.Null.And.Not.Empty); Assert.That(src.GetConfiguration(), Is.Not.EqualTo("Sample.json").And.EndWith("Sample.json")); Assert.That(src.GetResourceDirectory(), Is.Not.EqualTo("Printers").And.EndWith("Printers")); }
public void Parse_Empty() { var src = new ArgumentCollection(new string[0], '/', true); var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Assert.That(src.GetTimeout(), Is.EqualTo(30)); Assert.That(src.GetRetryCount(), Is.EqualTo(1)); Assert.That(src.GetCommand(), Is.Empty); Assert.That(src.GetConfiguration(), Is.Null); Assert.That(src.GetResourceDirectory(), Is.EqualTo(dir)); }
static int Main(string[] args) { try { Logger.Configure(); Logger.Info(LogType, Assembly.GetExecutingAssembly()); Logger.Info(LogType, $"[ {string.Join(" ", args)} ]"); Logger.Warn(LogType, () => { foreach (var e in Printer.GetElements()) { e.Log(); } }); var src = new ArgumentCollection(args, '/', true); var cmd = src.GetCommand(); if (src.Count <= 0) { Logger.Warn(LogType, "Configuration not found"); } else if (!cmd.HasValue()) { Logger.Warn(LogType, "Command not found"); } else if (cmd.FuzzyEquals("Install")) { Install(src, false); } else if (cmd.FuzzyEquals("Reinstall")) { Install(src, true); } else if (cmd.FuzzyEquals("Uninstall")) { Uninstall(src); } else { Logger.Warn(LogType, $"{cmd}:Unexpected command"); } return(0); } catch (Exception err) { Logger.Error(LogType, err); } return(-1); }