public static RenameOptionType GetOptionType(string option) { RenameOptionType optionType = RenameOptionType.None; foreach (var pair in Options) { foreach (var item in pair.Value) { if (item == option) { optionType = pair.Key; break; } } } return(optionType); }
private static RenameCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions) { if (commandLineOptions == null) { throw new CommandLineException(string.Format(CultureInfo.CurrentCulture, "Option used in invalid context -- {0}", "must specify a option.")); } RenameCommandLineOptions targetOptions = new RenameCommandLineOptions(); if (commandLineOptions.Arguments.Count >= 0) { foreach (var arg in commandLineOptions.Arguments.Keys) { RenameOptionType optionType = RenameOptions.GetOptionType(arg); if (optionType == RenameOptionType.None) { throw new CommandLineException( string.Format(CultureInfo.CurrentCulture, "Option used in invalid context -- {0}", string.Format(CultureInfo.CurrentCulture, "cannot parse the command line argument : [{0}].", arg))); } switch (optionType) { case RenameOptionType.RegexPattern: targetOptions.RegexPattern = commandLineOptions.Arguments[arg]; break; case RenameOptionType.InputDirectory: targetOptions.InputDirectory = commandLineOptions.Arguments[arg]; break; case RenameOptionType.Recursive: targetOptions.IsSetRecursive = true; break; case RenameOptionType.OutputPattern: targetOptions.OutputPattern = commandLineOptions.Arguments[arg]; break; case RenameOptionType.Folder: targetOptions.IsSetFolder = true; break; case RenameOptionType.Exclude: targetOptions.Excludes.AddRange( commandLineOptions.Arguments[arg].Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList()); break; case RenameOptionType.PadString: targetOptions.IsSetPadString = true; targetOptions.PadString = commandLineOptions.Arguments[arg]; break; case RenameOptionType.Help: targetOptions.IsSetHelp = true; break; case RenameOptionType.Version: targetOptions.IsSetVersion = true; break; } } } return(targetOptions); }