private static bool TryParseCommandLine(string[] args, out ParsedArgs parsedArgs, out CreateCommand func) { func = null; parsedArgs = new ParsedArgs(); // Setup the default values var binariesPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(AppContext.BaseDirectory)))); var index = 0; if (!TryParseCommon(args, ref index, parsedArgs)) { return false; } if (!TryParseCommand(args, ref index, out func)) { return false; } parsedArgs.SourcesDirectory = parsedArgs.SourcesDirectory ?? GetDirectoryName(AppContext.BaseDirectory, 5); parsedArgs.GenerateDirectory = parsedArgs.GenerateDirectory ?? parsedArgs.SourcesDirectory; parsedArgs.RepoUtilDataPath = parsedArgs.RepoUtilDataPath ?? Path.Combine(parsedArgs.SourcesDirectory, @"build\config\RepoUtilData.json"); parsedArgs.RemainingArgs = index >= args.Length ? Array.Empty<string>() : args.Skip(index).ToArray(); return true; }
public override string[] Execute(ParsedArgs args) { LDAP spnLookup = new LDAP(); List <string> userListWitSPNs = spnLookup.GetAccountsWithSPNs(); return(userListWitSPNs.ToArray()); }
public override string[] Execute(ParsedArgs args) { try { if (string.IsNullOrEmpty(args.ComputerName)) { throw new EDDException("ComputerName cannot be empty"); } Amass loggedInInfo = new Amass(); List <Amass.WKSTA_USER_INFO_1> loggedInAccounts = loggedInInfo.GetLoggedOnUsers(args.ComputerName); List <string> results = new List <string>(); foreach (Amass.WKSTA_USER_INFO_1 sessionInformation in loggedInAccounts) { results.Add($"Account Name: {sessionInformation.wkui1_username}"); results.Add($"Domain Used by Account: {sessionInformation.wkui1_logon_domain}"); results.Add($"Operating System Domains: {sessionInformation.wkui1_oth_domains}"); results.Add($"Logon server: {sessionInformation.wkui1_logon_server}"); } return(results.ToArray()); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
private static bool TryParseCommandLine(string[] args, out ParsedArgs parsedArgs, out CreateCommand func) { func = null; parsedArgs = new ParsedArgs(); // Setup the default values var binariesPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(AppContext.BaseDirectory)))); var index = 0; if (!TryParseCommon(args, ref index, parsedArgs)) { return(false); } if (!TryParseCommand(args, ref index, out func)) { return(false); } parsedArgs.SourcesDirectory = parsedArgs.SourcesDirectory ?? GetDirectoryName(AppContext.BaseDirectory, 5); parsedArgs.GenerateDirectory = parsedArgs.GenerateDirectory ?? parsedArgs.SourcesDirectory; parsedArgs.RepoUtilDataPath = parsedArgs.RepoUtilDataPath ?? Path.Combine(parsedArgs.SourcesDirectory, @"build\config\RepoUtilData.json"); parsedArgs.RemainingArgs = index >= args.Length ? Array.Empty <string>() : args.Skip(index).ToArray(); return(true); }
private static ParsedArgs ParseArgs(string[] args) { var pa = new ParsedArgs(); if (args.Length >= 2) { if (File.Exists(args[0])) { pa.TemplateFile = args[0]; } if (Directory.Exists(args[1])) { pa.TargetsDirectory = args[1]; } } if (pa.TemplateFile == null || pa.TargetsDirectory == null) { Console.WriteLine("Usage: FxCopUpdater [FxCop rules/exclusions file] [targets directory]"); Environment.Exit(1); } if (pa.TargetsDirectory.EndsWith("\\")) { pa.TargetsDirectory = pa.TargetsDirectory.TrimEnd('\\'); } return(pa); }
public MethodInvoker GetMethodInvoker(ParsedArgs args) { var argNames = args.Keys; if (args.Verb != Name || // Parameters.Count() != args.Count || Parameters.All(p => p.SupportsArgument(argNames)) == false) { return null; } var parameterValues = new List<object>(); foreach (var para in Parameters.OrderBy(p => p.Position)) { object invokeParam; var alias = para.GetSupportedAlias(argNames); // if null method argument was an optional argument, so pass default value. if (alias == null) invokeParam = para.DefaultValue; else { // check if parameter is an array if (para.IsArray) { invokeParam = para.GetParameterArray(args[alias].ToArray()); } else { invokeParam = para.GetParameter(args[alias].FirstOrDefault()); } } parameterValues.Add(invokeParam); } var invoker = new MethodInvoker(this, parameterValues.ToArray()); return invoker; }
static void Main(string[] args) { try { ParsedArgs parsedArgs = new ParsedArgs(args); ConsoleWriteWinMDTypes( parsedArgs, delegate(string line) { Console.WriteLine(line); }, delegate(string line) { if (parsedArgs.verbose) { Console.WriteLine(line); } }); } catch (Exception e) { Console.Error.WriteLine("Error: " + e.Message); Console.Error.WriteLine( "WinMDGraph (-file [WinMD path]|-match [regex]|-verbose)*\n" + "\t-file [WinMD file path] - Add metadata from the specified WinMD file\n" + "\t-match [WinMD file path] - Include types with matching full name\n" + "\t-verbose - Include extra verbose info in the output\n" ); } }
public override string[] Execute(ParsedArgs args) { LDAP findDCs = new LDAP(); List <string> domainControllers = findDCs.CaptureDomainControllers(); return(domainControllers.ToArray()); }
public override string[] Execute(ParsedArgs args) { LDAP domainQuery = new LDAP(); List <string> domainComputers = domainQuery.CaptureComputers(); return(domainComputers.ToArray()); }
private static bool TryParseCommon(string[] args, ref int index, ParsedArgs parsedArgs) { while (index < args.Length) { var arg = args[index]; if (arg[0] != '-') { return true; } index++; switch (arg.ToLower()) { case "-sourcesPath": { if (index < args.Length) { parsedArgs.SourcesPath = args[index]; index++; } else { Console.WriteLine($"The -sourcesPath switch needs a value"); return false; } break; } default: Console.Write($"Option {arg} is unrecognized"); return false; } } return true; }
public override string[] Execute(ParsedArgs args) { if (string.IsNullOrEmpty(args.UserName)) { Amass userInfo = new Amass(); List <string> allDomainUsers = userInfo.GetDomainUsersInfo(); return(allDomainUsers.ToArray()); } Amass singleUserInfo = new Amass(); UserObject soleUser = singleUserInfo.GetDomainUserInfo(args.UserName); List <string> domainUser = new List <string> { $"SamAccountName: {soleUser.SamAccountName}", $"Name: {soleUser.Name}", $"Description: {soleUser.Description}", $"Distinguished Name: {soleUser.DistinguishedName}", $"SID: {soleUser.SID}", }; string groups = "Domain Groups: "; foreach (string singleGroupName in soleUser.DomainGroups) { groups += $"{singleGroupName}, "; } groups = groups.TrimEnd(',', ' '); domainUser.Add(groups); return(domainUser.ToArray()); }
private static void UpdateProjectFile(ParsedArgs pa) { //load the project file var template = new System.Xml.XmlDocument(); template.Load(pa.TemplateFile); //update it RemoveTargets(template); AddTargets(template, pa.TargetsDirectory); UpdateReferencePaths(template); //write it back to disk var output = new System.Xml.XmlDocument(); foreach (var node in template.ChildNodes.Cast <XmlNode>().Where(w => w.NodeType != XmlNodeType.XmlDeclaration)) { var importNode = output.ImportNode(node, true); output.AppendChild(importNode); } using (var xWriter = XmlWriter.Create(pa.TemplateFile, new XmlWriterSettings() { Indent = true, IndentChars = " " })) { output.WriteTo(xWriter); } }
public ParsedArgs Parse(string[] args) { var parsed = new ParsedArgs(); for (int i = 0; i < args.Length; i++) { var arg = args[i]; if (arg.StartsWith("--")) { parsed.AddSwitch(arg.Substring(2)); } else if (arg.StartsWith("-")) { var valIndex = i + 1; if (valIndex >= args.Length) throw new OptionMissingValueException(arg.Substring(1)); var val = args[valIndex]; i += 1; parsed.AddOption(arg.Substring(1), val); } else { parsed.AddArg(arg); } } return parsed; }
private static bool TryParseCommandLine(string[] args, out ParsedArgs parsedArgs, out CreateCommand func) { func = null; parsedArgs = new ParsedArgs(); // Setup the default values parsedArgs.SourcesPath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); var index = 0; if (!TryParseCommon(args, ref index, parsedArgs)) { return false; } if (string.IsNullOrEmpty(parsedArgs.RepoDataPath)) throw new ArgumentException("The -repoDataPath switch is required."); if (!TryParseCommand(args, ref index, out func)) { return false; } parsedArgs.RemainingArgs = index >= args.Length ? Array.Empty<string>() : args.Skip(index).ToArray(); return true; }
public override string[] Execute(ParsedArgs args) { try { if (string.IsNullOrEmpty(args.ComputerName)) { throw new EDDException("ComputerName cannot be empty"); } Amass sessionInfo = new Amass(); List <Amass.SESSION_INFO_10> incomingSessions = sessionInfo.GetRemoteSessionInfo(args.ComputerName); List <string> results = new List <string>(); foreach (Amass.SESSION_INFO_10 sessionInformation in incomingSessions) { results.Add($"Connection From: {sessionInformation.sesi10_cname}"); results.Add($"Idle Time: {sessionInformation.sesi10_idle_time}"); results.Add($"Total Active Time: {sessionInformation.sesi10_time}"); results.Add($"Username: {sessionInformation.sesi10_username}"); } return(results.ToArray()); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
public override string[] Execute(ParsedArgs args) { Amass forestInfo = new Amass(); Forest currentForest = forestInfo.GetForestObject(); return(new string[] { currentForest.Name }); }
public override string[] Execute(ParsedArgs args) { LDAP computerQuery = new LDAP(); List <string> domainSystems = computerQuery.CaptureComputers(); Amass shareMe = new Amass(); List <string> allShares = shareMe.GetShares(domainSystems); return(allShares.ToArray()); }
public void consumeTestFalseOnNoLabelMatch() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-test"); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] {"-nottest"}, 0, 1); ParsedArgs pArgs = new ParsedArgs(); bool result = testDef.consume(vArgs, pArgs); Assert.IsFalse(result, "[ArgDef][consume] consume should return false when no label matches the input"); }
public void consumeTestFlag() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t" }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); Assert.IsTrue(pArgs.getValue<bool>("t"), "[ArgDef][consume] consume should set the appropriate value for the given arg name when encountered."); }
public override string[] Execute(ParsedArgs args) { try { Domain domain = Domain.GetCurrentDomain(); return(new string[] { domain.Name }); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
public override string[] Execute(ParsedArgs args) { if (string.IsNullOrEmpty(args.UserName)) { throw new EDDException("UserName cannot be empty"); } Amass sidConverter = new Amass(); string sid = sidConverter.GetUsernameFromSID(args.UserName); return(new string[] { sid }); }
public override string[] Execute(ParsedArgs args) { if (string.IsNullOrEmpty(args.ComputerName) || string.IsNullOrEmpty(args.GroupName)) { throw new EDDException("ComputerName and GroupName cannot be empty"); } Amass shepherd = new Amass(); List <string> localGroupMembers = shepherd.GetLocalGroupMembers(args.ComputerName, args.GroupName); return(localGroupMembers.ToArray()); }
public override string[] Execute(ParsedArgs args) { if (string.IsNullOrEmpty(args.DomainName)) { throw new EDDException("DomainName cannot be empty"); } LDAP ldapSIDFinder = new LDAP(); string sid = ldapSIDFinder.GetDomainSID(args.DomainName); return(new string[] { sid }); }
public override string[] Execute(ParsedArgs args) { if (string.IsNullOrEmpty(args.GroupName)) { throw new EDDException("GroupName cannot be empty"); } Amass groupMemberEnum = new Amass(); List <string> groupMembers = groupMemberEnum.GetDomainGroupMembers(args.GroupName); return(groupMembers.ToArray()); }
public override string[] Execute(ParsedArgs args) { if (string.IsNullOrEmpty(args.DomainName)) { throw new EDDException("DomainName cannot be empty"); } Amass domainGroupSid = new Amass(); string incomingSid = domainGroupSid.GetDomainGroupSID(args.DomainName); return(new string[] { incomingSid }); }
public override string[] Execute(ParsedArgs args) { try { Amass forestInfo = new Amass(); Forest currentForest = forestInfo.GetForestObject(); return(new string[] { currentForest.Name }); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
private static bool TryParseCommon(string[] args, ref int index, ParsedArgs parsedArgs) { while (index < args.Length) { var arg = args[index]; if (arg[0] != '-') { return(true); } index++; switch (arg.ToLower()) { case "-sourcespath": { if (index < args.Length) { parsedArgs.SourcesPath = args[index]; index++; } else { Console.WriteLine($"The -sourcesPath switch needs a value"); return(false); } break; } case "-config": { if (index < args.Length) { parsedArgs.RepoUtilDataPath = args[index]; index++; } else { Console.WriteLine($"The -config switch needs a value"); return(false); } break; } default: Console.Write($"Option {arg} is unrecognized"); return(false); } } return(true); }
public override string[] Execute(ParsedArgs args) { try { LDAP spnLookup = new LDAP(); List <string> userListWitSPNs = spnLookup.GetAccountsWithSPNs(); return(userListWitSPNs.ToArray()); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
public override string[] Execute(ParsedArgs args) { if (string.IsNullOrEmpty(args.ProcessName)) { throw new EDDException("ProcessName cannot be empty"); } LDAP procQuery = new LDAP(); List <string> procComputers = procQuery.CaptureComputers(); WMI processSearcher = new WMI(); List <string> systemsWithProc = processSearcher.CheckProcesses(procComputers, args.ProcessName); return(systemsWithProc.ToArray()); }
public override string[] Execute(ParsedArgs args) { Amass forestDomains = new Amass(); Forest theCurrentForest = forestDomains.GetForestObject(); DomainCollection forestDomainList = theCurrentForest.Domains; List <string> result = new List <string>(); foreach (Domain internalDomain in forestDomainList) { result.Add(internalDomain.Name); } return(result.ToArray()); }
public override string[] Execute(ParsedArgs args) { try { LDAP computerQuery = new LDAP(); List <string> domainSystems = computerQuery.CaptureComputers(); Amass shareMe = new Amass(); string[] allShares = shareMe.GetShares(domainSystems, args.Threads); return(allShares); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
public void consumeTestLabeledBoolAsArray() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.type = typeof(bool); testDef.argCount = 1; testDef.createArrayForArgCount1 = true; testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", "false" }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); bool[] result = pArgs.getArray<bool>("t"); Assert.AreEqual<int>(1, result.Length, "[ArgDef][consume] consume should create an array of size 1 when argCount is 1 and createArrayForArgCount1 is true"); Assert.IsFalse(result[0], "[ArgDef][consume] consume should set the appropriate value for the given arg name when encountered."); }
public override string[] Execute(ParsedArgs args) { try { if (!string.IsNullOrEmpty(args.GroupName) && !string.IsNullOrEmpty(args.UserName)) { throw new EDDException("Please use GroupName or UserName, not both"); } LDAP compQuery = new LDAP(); List <string> windowsComputers = compQuery.CaptureComputers(); if (windowsComputers.Count < 1) { throw new EDDException("No domain computers could be found"); } string[] results = new string[] { }; // if group and user is null, search for domain admins if (string.IsNullOrEmpty(args.GroupName) && string.IsNullOrEmpty(args.UserName)) { results = FindMembersOfGroup(windowsComputers, "Domain Admins"); } // if group is not null and user is null, search for group if (!string.IsNullOrEmpty(args.GroupName) && string.IsNullOrEmpty(args.UserName)) { results = FindMembersOfGroup(windowsComputers, args.GroupName); } // if group is null and user is not null, search for user if (string.IsNullOrEmpty(args.GroupName) && !string.IsNullOrEmpty(args.UserName)) { results = FindUser(windowsComputers, args.UserName); } return(results); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
public override string[] Execute(ParsedArgs args) { try { if (string.IsNullOrEmpty(args.GroupName)) { throw new EDDException("GroupName cannot be empty"); } Amass groupMemberEnum = new Amass(); List <string> groupMembers = groupMemberEnum.GetDomainGroupMembers(args.GroupName); return(groupMembers.ToArray()); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
public override string[] Execute(ParsedArgs args) { try { if (string.IsNullOrEmpty(args.ComputerName) || string.IsNullOrEmpty(args.GroupName)) { throw new EDDException("ComputerName and GroupName cannot be empty"); } Amass shepherd = new Amass(); List <string> localGroupMembers = shepherd.GetLocalGroupMembers(args.ComputerName, args.GroupName); return(localGroupMembers.ToArray()); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
public override string[] Execute(ParsedArgs args) { try { if (string.IsNullOrEmpty(args.UserName)) { throw new EDDException("UserName cannot be empty"); } Amass sidConverter = new Amass(); string sid = sidConverter.GetUsernameFromSID(args.UserName); return(new string[] { sid }); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
public override string[] Execute(ParsedArgs args) { try { if (string.IsNullOrEmpty(args.DomainName)) { throw new EDDException("DomainName cannot be empty"); } Amass domainGroupSid = new Amass(); string incomingSid = domainGroupSid.GetDomainGroupSID(args.DomainName); return(new string[] { incomingSid }); } catch (Exception e) { return(new string[] { "[X] Failure to enumerate info - " + e }); } }
public virtual bool consume(VirtualArray<string> vArgs, ParsedArgs pArgs) { if (!isConsumeable(vArgs)) { return false; } pArgs.add(name, getValue(vArgs)); if (argCountIsRemainderOfArgs) { vArgs.moveStart(vArgs.endIndexExclusive); } else { vArgs.moveStartBy(argCount + 1); } return true; }
private static ParsedArgs ParseArgs(string[] args) { var pa = new ParsedArgs(); if (args.Length >= 2) { if (File.Exists(args[0])) pa.TemplateFile = args[0]; if (Directory.Exists(args[1])) pa.TargetsDirectory = args[1]; } if (pa.TemplateFile == null || pa.TargetsDirectory == null) { Console.WriteLine("Usage: FxCopUpdater [FxCop rules/exclusions file] [targets directory]"); Environment.Exit(1); } if (pa.TargetsDirectory.EndsWith("\\")) pa.TargetsDirectory = pa.TargetsDirectory.TrimEnd('\\'); return pa; }
public virtual ParsedArgs parseArgs(string[] args) { // setup stuff ParsedArgs pArgs = new ParsedArgs(); int orderedArgDefIx = 0; initArgDefs(); VirtualArray<string> vArgs = new VirtualArray<string>(args); // while (vArgs.length > 0) { bool argConsumed = false; for (int i = 0; !argConsumed && i < labeledArgDefs.Count; i++) { ArgDef def = labeledArgDefs[i]; argConsumed = def.consume(vArgs, pArgs); // test crap if (argConsumed) { Console.WriteLine(string.Format("[TEMP DEBUG] LArg '{0}' was consumed", def.name)); } // if (def.errorOccured()) { pArgs.addErrorMessages(def.getErrorMessages()); vArgs.moveStart(vArgs.endIndexExclusive); // this exits the outer while loop } } if (!argConsumed) { if (orderedArgDefIx >= orderedArgDefs.Count) { pArgs.addErrorMessage("Encountered more args than expected."); break; } ArgDef oDef = orderedArgDefs[orderedArgDefIx]; argConsumed = oDef.consume(vArgs, pArgs); orderedArgDefIx++; if (oDef.errorOccured()) { pArgs.addErrorMessages(oDef.getErrorMessages()); vArgs.moveStart(vArgs.endIndexExclusive); // this exits the outer while loop } else if (!argConsumed) { pArgs.addErrorMessage(string.Format("Unable to use arg '{0}'", vArgs[0])); vArgs.moveStart(vArgs.endIndexExclusive); // this exits the outer while loop } // test crap else { Console.WriteLine(string.Format("[Temp Debug] OArg '{0}' was consumed", oDef.name)); } // } } // end while if (pArgs.errorOccured()) { if (printErrorMessageOnInvalidArgs) { foreach (string message in pArgs.getErrorMessages()) { Console.WriteLine(message); } } if (printUsageOnInvalidArgs) { Console.WriteLine(getUsageString()); } } else { finishArgDefs(pArgs); } return pArgs; }
private static void UpdateProjectFile(ParsedArgs pa) { //load the project file var template = new System.Xml.XmlDocument(); template.Load(pa.TemplateFile); //update it RemoveTargets(template); AddTargets(template, pa.TargetsDirectory); UpdateReferencePaths(template); //write it back to disk var output = new System.Xml.XmlDocument(); foreach (var node in template.ChildNodes.Cast<XmlNode>().Where(w => w.NodeType != XmlNodeType.XmlDeclaration)) { var importNode = output.ImportNode(node, true); output.AppendChild(importNode); } using (var xWriter = XmlWriter.Create(pa.TemplateFile, new XmlWriterSettings() { Indent = true, IndentChars = " " })) { output.WriteTo(xWriter); } }
public void consumeTestListOfDouble() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.type = typeof(double); testDef.argCount = 3; testDef.parseInit(ArgTypeParser.basicParsers); double[] testVals = new double[] { -234.556, 0, 234234.234 }; VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", testVals[0].ToString(), testVals[1].ToString(), testVals[2].ToString() }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); double[] result = pArgs.getArray<double>("t"); int i = 0; foreach (double val in result) { Assert.AreEqual<double>(testVals[i], val, "[ArgDef][consume] consume resulted in an array with unexpected values."); i++; } }
public void consumeTestListOfString() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.argCount = 5; testDef.parseInit(ArgTypeParser.basicParsers); string[] testVals = new string[] { "ok", "", "what ", "yeyeah", "turn down" }; VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", testVals[0].ToString(), testVals[1].ToString(), testVals[2].ToString(), testVals[3].ToString(), testVals[4].ToString() }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); string[] result = pArgs.getArray<string>("t"); int i = 0; foreach (string val in result) { Assert.AreEqual<string>(testVals[i], val, "[ArgDef][consume] consume resulted in an array with unexpected values."); i++; } }
public void consumeTestWrongNumberOfFollowingArgs() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-test"); testDef.argCount = 2; testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-test", "a" }, 0, 2); ParsedArgs pArgs = new ParsedArgs(); bool result = testDef.consume(vArgs, pArgs); bool errors = testDef.errorOccured(); Assert.IsFalse(result, "[ArgDef][consume] consume should return false when there are less remaining args than argCount."); Assert.IsTrue(errors, "[ArgDef][consume] consume should generate an error message when there are less remaining args than argCount."); }
public void consumeTestLabeledDouble() { ArgDef testDef = new ArgDef(); testDef.argLabels.Add("-t"); testDef.type = typeof(double); testDef.argCount = 1; testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "-t", "33.3" }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); Assert.AreEqual(33.3, pArgs.getValue<double>("t"), 0.01, "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); }
private void finishArgDefs(ParsedArgs pArgs) { foreach (ArgDef def in labeledArgDefs) { def.parseFinish(pArgs); } foreach (ArgDef def in orderedArgDefs) { def.parseFinish(pArgs); } }
public void consumeTestNoVArgs() { ArgDef testDef = new ArgDef(); testDef.name = "test"; testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[]{}, 0, 0); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); }
public virtual void parseFinish(ParsedArgs pArgs) { if (instanceCount < 1 && required) { errorMessages.Add(string.Format("The '{0}' argument is required.")); return; } if (instanceCount == 0 && (defaultValue != null || useDefaultIfNull)) { pArgs.add(name, defaultValue); } }
public void consumeTestMultipleOptionEncounters() { ArgDef testDef = new ArgDef(); testDef.argLabels.AddRange(new string[]{"-test", "-t"}); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] {"-test", "-t"}, 0, 2); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); bool result2 = testDef.consume(vArgs, pArgs); bool errors = testDef.errorOccured(); Assert.IsFalse(result2, "[ArgDef][consume] consume should return false when a label is encountered twice."); Assert.IsTrue(errors, "[ArgDef][consume] consume should generate an error message when a label is encountered twice."); }
public void consumeTestOrderedInt() { ArgDef testDef = new ArgDef(); testDef.name = "test"; testDef.type = typeof(int); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "33" }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("test"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); Assert.AreEqual<int>(33, pArgs.getValue<int>("test"), "[ArgDef][consume] consume should set the appropriate value for the given arg name when encountered."); }
public void consumeTestRemainingString() { ArgDef testDef = new ArgDef(); testDef.name = "t"; testDef.argCountIsRemainderOfArgs = true; testDef.parseInit(ArgTypeParser.basicParsers); string[] testVals = new string[] { "what", "the", "french toast" }; VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { testVals[0].ToString(), testVals[1].ToString(), testVals[2].ToString() }); ParsedArgs pArgs = new ParsedArgs(); testDef.consume(vArgs, pArgs); Assert.IsTrue(pArgs.containsKey("t"), "[ArgDef][consume] consume should add a value to the passed in ParsedArgs when the appropriate args are given"); string[] result = pArgs.getArray<string>("t"); int i = 0; foreach (string val in result) { Assert.AreEqual<string>(testVals[i], val, "[ArgDef][consume] consume resulted in an array with unexpected values."); i++; } }
public void consumeTestOrderedEncounteredWrongType() { ArgDef testDef = new ArgDef(); testDef.name = "test"; testDef.type = typeof(int); testDef.parseInit(ArgTypeParser.basicParsers); VirtualArray<string> vArgs = new VirtualArray<string>(new string[] { "a" }, 0, 1); ParsedArgs pArgs = new ParsedArgs(); bool result = testDef.consume(vArgs, pArgs); bool errors = testDef.errorOccured(); Assert.IsFalse(result, "[ArgDef][consume] consume should return false when the args provided don't match the arg def's type."); Assert.IsTrue(errors, "[ArgDef][consume] consume should generate an error when the args provided don't match the arg def's type."); }
static ParsedArgs ParseArgs(string[] args) { var parsedArgs = new ParsedArgs(); // The first argument is always the 'verb' unless it starts with a hyphen. var first = args.FirstOrDefault(); int skip = 0; if (first != null && !first.StartsWith("-")) { parsedArgs.Verb = first; skip = 1; } string currentSwitch = ""; foreach (var arg in args.Skip(skip)) { if (arg.StartsWith("-")) { // arguments to a switch can be space or colon seperated. Colon args are found first. var splits = arg.Split(':'); currentSwitch = splits.First().Substring(1).ToLower(); var switchArgs = splits.Skip(1).ToList(); parsedArgs.Add(currentSwitch, switchArgs); } else { List<string> switchArgs; if (!parsedArgs.TryGetValue(currentSwitch, out switchArgs)) { switchArgs = new List<string>(); parsedArgs.Add(currentSwitch, switchArgs); } switchArgs.Add(arg); } } return parsedArgs; }