Ejemplo n.º 1
0
        public override void Execute()
        {
            base.Execute();

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

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

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

            Terminate();
        }
Ejemplo n.º 2
0
 private static void CheckOptions(FindCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
     {
         if (!checkedOptions.IsSetDirectory || string.IsNullOrEmpty(checkedOptions.Directory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a directory."));
         }
         if (!checkedOptions.IsSetRegexPattern || string.IsNullOrEmpty(checkedOptions.RegexPattern))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify regex pattern for matching."));
         }
     }
 }
Ejemplo n.º 3
0
    public override void Execute()
    {
      base.Execute();

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

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

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

            FindCommandLineOptions targetOptions = new FindCommandLineOptions();

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

                    case FindOptionType.Directory:
                        targetOptions.IsSetDirectory = true;
                        targetOptions.Directory      = commandLineOptions.Arguments[arg];
                        break;

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

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

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

            if (commandLineOptions.Parameters.Count > 0)
            {
                if (!targetOptions.IsSetDirectory)
                {
                    targetOptions.IsSetDirectory = true;
                    targetOptions.Directory      = commandLineOptions.Parameters.First();
                }

                if (commandLineOptions.Parameters.Count >= 2)
                {
                    if (!targetOptions.IsSetRegexPattern)
                    {
                        targetOptions.IsSetRegexPattern = true;
                        targetOptions.RegexPattern      = commandLineOptions.Parameters.ElementAt(1);
                    }
                }
            }

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

      FindCommandLineOptions targetOptions = new FindCommandLineOptions();

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

      if (commandLineOptions.Parameters.Count > 0)
      {
        if (!targetOptions.IsSetDirectory)
        {
          targetOptions.IsSetDirectory = true;
          targetOptions.Directory = commandLineOptions.Parameters.First();
        }

        if (commandLineOptions.Parameters.Count >= 2)
        {
          if (!targetOptions.IsSetRegexPattern)
          {
            targetOptions.IsSetRegexPattern = true;
            targetOptions.RegexPattern = commandLineOptions.Parameters.ElementAt(1);
          }
        }
      }

      return targetOptions;
    }