/// <summary> /// Sets up logging and prepares to use the sysetm. /// </summary> protected void Process(string [] args) { // Build up the arguments and process ourselves CommandLineArguments cla = new CommandLineArguments(args); SetArgumentParameters(cla); try { cla.Process(this); } catch (Exception e) { Usage(this, e.Message, e); return; } // Register the tools RegisterTools(); // Process the command-line ProcessCommand(cla); }
public void TestSinglePositionalPlus() { CommandLineArguments cla = new CommandLineArguments(new string [] { "arg", "bob", }); // Pre-testing Assert.AreEqual(2, cla.RemainingArguments.Count); Assert.AreEqual("arg", cla.RemainingArguments[0].ToString()); Assert.AreEqual("bob", cla.RemainingArguments[1].ToString()); // Process it Container2 c2 = new Container2(); cla.Process(c2); // Check it Assert.AreEqual(1, cla.RemainingArguments.Count); Assert.AreEqual("bob", cla.RemainingArguments[0].ToString()); Assert.AreEqual("arg", c2.Positional1); }
public void TestMissingPositional() { CommandLineArguments cla = new CommandLineArguments(new string [] {}); // Pre-testing Assert.AreEqual(0, cla.RemainingArguments.Count); // Process it Container2 c2 = new Container2(); cla.Process(c2); }
public void TestC1F1() { CommandLineArguments cla = new CommandLineArguments(new string [] { "--c1f1=bob", "gary", }); cla.Scanners.Add(LongArgumentScanner.DoubleDash); // Verify the initial counts Assert.AreEqual(2, cla.RemainingArguments.Count); Assert.AreEqual("--c1f1=bob", cla.RemainingArguments[0].ToString()); // Process it Container1 c1 = new Container1(); cla.Process(c1); Assert.AreEqual(1, cla.RemainingArguments.Count, "Number of arguments"); Assert.AreEqual("gary", cla.RemainingArguments[0].ToString(), "Next non-processed argument"); Assert.AreEqual("bob", c1.f1, "Value in the container1"); }
/// <summary> /// Process the command based on the arguments. /// </summary> private void ProcessCommand(CommandLineArguments cla) { // Check for length if (cla.RemainingArguments.Count == 0) { Usage(this, "A tool name is required.", null); return; } // Go through and get it string toolName = (string) cla.RemainingArguments[0]; cla.RemainingArguments.RemoveAt(0); ITool tool = (ITool) tools[toolName]; if (tool == null) { Usage(this, String.Format("Cannot find a tool named '{0}'.", toolName), null); return; } // Process the command, both automatically and the results try { cla.Process(tool); } catch (Exception e) { Usage(tool, e.Message, e); return; } // Execute the tool tool.Process((string []) cla.RemainingArguments .ToArray(typeof(string))); }