private static MoveDateCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions) { if (commandLineOptions == null) { throw new CommandLineException(string.Format(CultureInfo.CurrentCulture, "Option used in invalid context -- {0}", "must specify a option.")); } MoveDateCommandLineOptions targetOptions = new MoveDateCommandLineOptions(); if (commandLineOptions.Arguments.Count >= 0) { foreach (var arg in commandLineOptions.Arguments.Keys) { MoveDateOptionType optionType = MoveDateOptions.GetOptionType(arg); if (optionType == MoveDateOptionType.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 MoveDateOptionType.RegexPattern: targetOptions.RegexPattern = commandLineOptions.Arguments[arg]; break; case MoveDateOptionType.InputDirectory: targetOptions.InputDirectory = commandLineOptions.Arguments[arg]; break; case MoveDateOptionType.Help: targetOptions.IsSetHelp = true; break; case MoveDateOptionType.Version: targetOptions.IsSetVersion = true; break; } } } return(targetOptions); }
public static MoveDateOptionType GetOptionType(string option) { MoveDateOptionType optionType = MoveDateOptionType.None; foreach (var pair in Options) { foreach (var item in pair.Value) { if (item == option) { optionType = pair.Key; break; } } } return(optionType); }