public override void Execute()
        {
            base.Execute();

            List <string>      singleOptionList = RemoveDirectoryOptions.GetSingleOptions();
            CommandLineOptions cloptions        = CommandLineParser.Parse(Arguments.ToArray <string>(), singleOptionList.ToArray());

            options = ParseOptions(cloptions);
            CheckOptions(options);

            if (options.IsSetHelp)
            {
                RaiseCommandLineUsage(this, RemoveDirectoryOptions.Usage);
            }
            else if (options.IsSetVersion)
            {
                RaiseCommandLineUsage(this, Version);
            }
            else
            {
                StartRemoveDirectory();
            }

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

            RemoveDirectoryCommandLineOptions targetOptions = new RemoveDirectoryCommandLineOptions();

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

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

                    case RemoveDirectoryOptionType.RegexPattern:
                        targetOptions.RegexPattern = commandLineOptions.Arguments[arg];
                        break;

                    case RemoveDirectoryOptionType.FixedString:
                        targetOptions.IsSetFixedString = true;
                        break;

                    case RemoveDirectoryOptionType.Empty:
                        targetOptions.IsSetEmpty = true;
                        break;

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

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

            return(targetOptions);
        }
 private static void CheckOptions(RemoveDirectoryCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
     {
         if (string.IsNullOrEmpty(checkedOptions.Directory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a directory."));
         }
         if (string.IsNullOrEmpty(checkedOptions.RegexPattern))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a pattern for matching."));
         }
     }
 }
Exemplo n.º 4
0
        public override void Execute()
        {
            base.Execute();

              List<string> singleOptionList = RemoveDirectoryOptions.GetSingleOptions();
              CommandLineOptions cloptions = CommandLineParser.Parse(Arguments.ToArray<string>(), singleOptionList.ToArray());
              options = ParseOptions(cloptions);
              CheckOptions(options);

              if (options.IsSetHelp)
              {
            RaiseCommandLineUsage(this, RemoveDirectoryOptions.Usage);
              }
              else if (options.IsSetVersion)
              {
            RaiseCommandLineUsage(this, Version);
              }
              else
              {
            StartRemoveDirectory();
              }

              Terminate();
        }
Exemplo n.º 5
0
 private static void CheckOptions(RemoveDirectoryCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
       {
     if (string.IsNullOrEmpty(checkedOptions.Directory))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a directory."));
     }
     if (string.IsNullOrEmpty(checkedOptions.RegexPattern))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a pattern for matching."));
     }
       }
 }
Exemplo n.º 6
0
        private static RemoveDirectoryCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
            throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
              "Option used in invalid context -- {0}", "must specify a option."));

              RemoveDirectoryCommandLineOptions targetOptions = new RemoveDirectoryCommandLineOptions();

              if (commandLineOptions.Arguments.Count >= 0)
              {
            foreach (var arg in commandLineOptions.Arguments.Keys)
            {
              RemoveDirectoryOptionType optionType = RemoveDirectoryOptions.GetOptionType(arg);
              if (optionType == RemoveDirectoryOptionType.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 RemoveDirectoryOptionType.Directory:
              targetOptions.Directory = commandLineOptions.Arguments[arg];
              break;
            case RemoveDirectoryOptionType.Recursive:
              targetOptions.IsSetRecursive = true;
              break;
            case RemoveDirectoryOptionType.RegexPattern:
              targetOptions.RegexPattern = commandLineOptions.Arguments[arg];
              break;
            case RemoveDirectoryOptionType.FixedString:
              targetOptions.IsSetFixedString = true;
              break;
            case RemoveDirectoryOptionType.Empty:
              targetOptions.IsSetEmpty = true;
              break;
            case RemoveDirectoryOptionType.Help:
              targetOptions.IsSetHelp = true;
              break;
            case RemoveDirectoryOptionType.Version:
              targetOptions.IsSetVersion = true;
              break;
              }
            }
              }

              return targetOptions;
        }