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