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

            CatCommandLineOptions targetOptions = new CatCommandLineOptions();

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

                    case CatOptionType.LineNumber:
                        targetOptions.IsSetLineNumber = true;
                        break;

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

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

            if (commandLineOptions.Parameters.Count > 0)
            {
                if (string.IsNullOrEmpty(targetOptions.InputFile))
                {
                    targetOptions.InputFile = commandLineOptions.Parameters.First();
                }
            }

            return(targetOptions);
        }