// --------------------------------------------------------------------- #region TestSelf // --------------------------------------------------------------------- /// <summary> /// Simple self test. /// </summary> /// <returns>bool - true for success, false for failure.</returns> public static bool TestSelf() { Logger log = new Logger("testSelf"); log.Verbosity = VerbosityLevel.Debug; log.Info("Starting..."); // // try parseSpec endCapStyle // string parseSpec = "file=s, type:s, v, d, number=s"; string[] testArgs = {"-file", "fileName", "-type", "-v", "hello", "-number", "-3.2"}; string errorMessage = null; Opts opts = new Opts(); opts.ParseSpec = parseSpec; log.Info("ParseSpec:"); opts.DisplayParseSpec(" "); if (!opts.Parse(testArgs, out errorMessage)) { log.Error("Unable to parse test string."); log.Error("Error message is '{0}'", errorMessage); return(false); } log.Info("After parse:"); opts.Display(" "); // check results if (opts.Options["file"] == null) { log.Error("Parse didn't get -file option"); return(false); } log.Info("-file argument was {0}", opts.Options["file"]); if (opts.Options.ContainsKey("v")) log.Info("-v option was found"); else { log.Error("Parse didn't find -v option"); return(false); } if (opts.Options.ContainsKey("type")) { log.Info("-type arg was '{0}'", opts.Options["type"]); } else { log.Error("Parse didn't find -type option"); return(false); } // // try usageSpec endCapStyle // log.Info("----------------------------------------------------------"); log.Info("UsageSpec style of use."); string usageSpec = "cmd -file fileName -type [typeName] [-v|-d] [-number num] file ..."; log.Info("Input usage: {0}", usageSpec); opts.UsageSpec = usageSpec; log.Info("UsageSpec:"); opts.DisplayParseSpec(" "); if (!opts.Parse(testArgs, out errorMessage)) { log.Error("Unable to parse test string."); log.Error("Error message is '{0}'", errorMessage); return(false); } if (opts.Options.ContainsKey("v")) { log.Info("-v was specified"); } log.Info("After parse:"); opts.Display(" "); // done log.Info("Done."); return(true); }
// --------------------------------------------------------------------- #region TestSelf // --------------------------------------------------------------------- /// <summary> /// Simple self test. /// </summary> /// <returns>bool - true for success, false for failure.</returns> public static bool TestSelf() { Logger log = new Logger("testSelf"); log.Verbosity = VerbosityLevel.Debug; log.Info("Starting..."); // // try parseSpec endCapStyle // string parseSpec = "file=s, type:s, v, d, number=s"; string[] testArgs = { "-file", "fileName", "-type", "-v", "hello", "-number", "-3.2" }; string errorMessage = null; Opts opts = new Opts(); opts.ParseSpec = parseSpec; log.Info("ParseSpec:"); opts.DisplayParseSpec(" "); if (!opts.Parse(testArgs, out errorMessage)) { log.Error("Unable to parse test string."); log.Error("Error message is '{0}'", errorMessage); return(false); } log.Info("After parse:"); opts.Display(" "); // check results if (opts.Options["file"] == null) { log.Error("Parse didn't get -file option"); return(false); } log.Info("-file argument was {0}", opts.Options["file"]); if (opts.Options.ContainsKey("v")) { log.Info("-v option was found"); } else { log.Error("Parse didn't find -v option"); return(false); } if (opts.Options.ContainsKey("type")) { log.Info("-type arg was '{0}'", opts.Options["type"]); } else { log.Error("Parse didn't find -type option"); return(false); } // // try usageSpec endCapStyle // log.Info("----------------------------------------------------------"); log.Info("UsageSpec style of use."); string usageSpec = "cmd -file fileName -type [typeName] [-v|-d] [-number num] file ..."; log.Info("Input usage: {0}", usageSpec); opts.UsageSpec = usageSpec; log.Info("UsageSpec:"); opts.DisplayParseSpec(" "); if (!opts.Parse(testArgs, out errorMessage)) { log.Error("Unable to parse test string."); log.Error("Error message is '{0}'", errorMessage); return(false); } if (opts.Options.ContainsKey("v")) { log.Info("-v was specified"); } log.Info("After parse:"); opts.Display(" "); // done log.Info("Done."); return(true); }