Exemplo n.º 1
0
        private static ExtractCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Option used in invalid context -- {0}", "must specify a option."));
            }

            ExtractCommandLineOptions targetOptions = new ExtractCommandLineOptions();

            if (commandLineOptions.Arguments.Count >= 0)
            {
                foreach (var arg in commandLineOptions.Arguments.Keys)
                {
                    ExtractOptionType optionType = ExtractOptions.GetOptionType(arg);
                    if (optionType == ExtractOptionType.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 ExtractOptionType.RegexPattern:
                        targetOptions.RegexPattern = commandLineOptions.Arguments[arg];
                        break;

                    case ExtractOptionType.InputDirectory:
                        targetOptions.InputDirectory = commandLineOptions.Arguments[arg];
                        break;

                    case ExtractOptionType.Recursive:
                        targetOptions.IsSetRecursive = true;
                        break;

                    case ExtractOptionType.InputFileExtensionFilter:
                        targetOptions.InputFileExtensionFilter.AddRange(
                            commandLineOptions.Arguments[arg].Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList());
                        break;

                    case ExtractOptionType.OutputDirectory:
                        targetOptions.OutputDirectory = commandLineOptions.Arguments[arg];
                        break;

                    case ExtractOptionType.OutputFileExtension:
                        targetOptions.OutputFileExtension = commandLineOptions.Arguments[arg].Trim();
                        break;

                    case ExtractOptionType.Exclude:
                        targetOptions.Excludes.AddRange(
                            commandLineOptions.Arguments[arg].Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList());
                        break;

                    case ExtractOptionType.Help:
                        targetOptions.IsSetHelp = true;
                        break;

                    case ExtractOptionType.Version:
                        targetOptions.IsSetVersion = true;
                        break;
                    }
                }
            }

            return(targetOptions);
        }