public static ParsedCmdLineArgs Parse(string[] args) { //Local list that we can work on var listArgs = args.ToList(); var result = new ParsedCmdLineArgs(); //Check if we have any silent args. If we do then remove them from the list and carry on var silentArgs = listArgs.Intersect(CmdLineArgsDefinition.SilentArgsVariants); result.SilentModeEnabled = silentArgs.Any(); listArgs.RemoveAll(a => silentArgs.Contains(a)); //We only support one extra arg for now so anything that's left over must be the folder path result.FileName = listArgs.FirstOrDefault(); return(result); }
public static ParsedCmdLineArgs Parse(string[] args) { var result = new ParsedCmdLineArgs(); //Check if we have any args foreach (string arg in args) { if (arg.StartsWith("-")) { // this is a switch Action <ParsedCmdLineArgs> a; if (ParsedCmdLineArgs.Args.TryGetValue(arg, out a)) { a(result); } else { throw new InvalidCmdLineException(string.Format(Resources.InvalidSwitchError, arg)); } } else { if (result.FileName == null) { result.FileName = arg; } else { throw new InvalidCmdLineException(Resources.TooManyFilenamesError); } } } if (result.FileName == null) { throw new InvalidCmdLineException(Resources.NoFilenamesSpecified); } return(result); }