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

            RemoveCommandLineOptions targetOptions = new RemoveCommandLineOptions();

            if (commandLineOptions.Arguments.Count >= 0)
            {
                foreach (var arg in commandLineOptions.Arguments.Keys)
                {
                    RemoveOptionType optionType = RemoveOptions.GetOptionType(arg);
                    if (optionType == RemoveOptionType.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 RemoveOptionType.Directory:
                        targetOptions.IsSetDirectory = true;
                        targetOptions.Directory      = commandLineOptions.Arguments[arg];
                        break;

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

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

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

            if (commandLineOptions.Parameters.Count > 0)
            {
                foreach (var item in commandLineOptions.Parameters)
                {
                    targetOptions.Files.Add(item);
                }
            }

            return(targetOptions);
        }
示例#2
0
        public static RemoveOptionType GetOptionType(string option)
        {
            RemoveOptionType optionType = RemoveOptionType.None;

            foreach (var pair in Options)
            {
                foreach (var item in pair.Value)
                {
                    if (item == option)
                    {
                        optionType = pair.Key;
                        break;
                    }
                }
            }

            return(optionType);
        }