public static ApplicationArguments ParseApplicationArguments(string[] arguments) { bool shouldDisplayHelpInstructions = arguments == null || arguments.Length == 0; int numberOfMessagesToWrite = 0; int numberOfMillisecondsToRunFor = 0; OutputTypes outputType = OutputTypes.Output; string standardOutputString = "Default standard output message."; string standardErrorString = "Default standard error message."; int exitCode = 0; bool shouldThrowException = false; string exceptionMessage = "Default exception message."; int delayBetweenMessagesInMilliseconds = 1000; for (int index = 0; index < arguments.Length; index++) { var argument = arguments[index]; var nextArgument = (index + 1 < arguments.Length) ? arguments[index + 1] : string.Empty; switch (argument.ToLower()) { case "/n": case "/number": numberOfMessagesToWrite = int.Parse(nextArgument); index++; break; case "/t": case "/time": numberOfMillisecondsToRunFor = int.Parse(nextArgument); index++; break; case "/ot": case "/outputtype": switch (nextArgument.ToLower()) { case "all": outputType = OutputTypes.All; break; case "error": outputType = OutputTypes.Error; break; default: outputType = OutputTypes.Output; break; } index++; break; case "/om": case "/outputmessage": standardOutputString = nextArgument; index++; break; case "/em": case "/errormessage": standardErrorString = nextArgument; index++; break; case "/ec": case "/exitcode": exitCode = int.Parse(nextArgument); index++; break; case "/te": case "/throwexception": shouldThrowException = true; break; case "/exm": case "/exceptionmessage": exceptionMessage = nextArgument; index++; break; case "/d": case "/delay": delayBetweenMessagesInMilliseconds = int.Parse(nextArgument); index++; break; default: Console.Error.WriteLine($"An invalid argument of '{argument}' was provided."); shouldDisplayHelpInstructions = true; break; } } var applicationArguments = new ApplicationArguments( shouldDisplayApplicationHelpInstructions: shouldDisplayHelpInstructions, numberOfMessagesToWrite: numberOfMessagesToWrite, numberOfMillisecondsToRunFor: numberOfMillisecondsToRunFor, outputType: outputType, standardOutputString: standardOutputString, standardErrorString: standardErrorString, exitCode: exitCode, shouldThrowException: shouldThrowException, exceptionMessage: exceptionMessage, delayBetweenMessagesInMilliseconds: delayBetweenMessagesInMilliseconds); return(applicationArguments); }
public ContinualOutputRunner(string[] args) { ApplicationArguments = ApplicationArgumentsParser.ParseApplicationArguments(args); }