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