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