예제 #1
0
        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);
        }
예제 #2
0
        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);
        }