public void ArgParse_Parse_Success() { ArgParse argParse = new ArgParse(); Option option = new Option("-a", "--add", "Add an option", true, true); Option option2 = new Option("-d", "--delete", "Delete an option", false, true); OptionSet optionSet = new OptionSet("Two parameters"); optionSet.Add(option); optionSet.Add(option2); argParse.Add(optionSet); OptionSet optionSet2 = new OptionSet("One parameter"); Option option3 = new Option("-v", "--version", "Version of the application", true, false); optionSet2.Add(option3); argParse.Add(optionSet2); string[] args = { "-a", "anOption" }; argParse.Parse(args); OptionSet activeOptionSet = argParse.GetActiveOptionSet(); if (activeOptionSet != null) { Assert.AreEqual("Two parameters", activeOptionSet.Name); } else { Assert.Fail(); } }
public void ArgParse_Parse_EmptyArgs() { ArgParse argParse = new ArgParse() { new OptionSet("One parameter") { new Option("-v", "--version", "Version of the application", true, false) } }; string[] args = {}; Assert.Throws <ArgumentException>(() => argParse.Parse(args)); }
public void ArgParse_Parse_onearg_Fail() { ArgParse argParse = new ArgParse(); Option option = new Option("-a", "--add", "Add an option", true, true); Option option2 = new Option("-d", "--delete", "Delete an option", false, true); OptionSet optionSet = new OptionSet("Two parameters"); optionSet.Add(option); optionSet.Add(option2); argParse.Add(optionSet); OptionSet optionSet2 = new OptionSet("One parameter"); Option option3 = new Option("-v", "--version", "Version of the application", true, false); optionSet2.Add(option3); argParse.Add(optionSet2); string[] args2 = { "-d", "anOption" }; Assert.Throws <ArgumentException>(() => argParse.Parse(args2)); }
private void Execute() { try { argParse.Parse(args); } catch (ArgumentException e) { argParse.Usage(); return; } OptionSet activeOptionSet = argParse.GetActiveOptionSet(); Console.Out.WriteLine("Active optionset: " + activeOptionSet.Name); if (activeOptionSet.Name.Equals("Analysis command")) { Option option = activeOptionSet.GetOption("-i"); Console.Out.WriteLine("input: " + option.ParamValue); option = activeOptionSet.GetOption("-o"); Console.Out.WriteLine("output: " + option.ParamValue); option = activeOptionSet.GetOption("-t"); Console.Out.WriteLine("trend: " + (option.IsProvided ? "true" : "false")); } }