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