コード例 #1
0
        public override void Execute()
        {
            base.Execute();

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

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

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

            Terminate();
        }
コード例 #2
0
 private static void CheckOptions(RenameCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
     {
         if (string.IsNullOrEmpty(checkedOptions.RegexPattern))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a regex pattern."));
         }
         if (string.IsNullOrEmpty(checkedOptions.InputDirectory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a input directory."));
         }
         if (!Directory.Exists(checkedOptions.InputDirectory))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "no such input directory."));
         }
         if (checkedOptions.IsSetPadString)
         {
             if (string.IsNullOrEmpty(checkedOptions.PadString))
             {
                 throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                              "Option used in invalid context -- {0}", "bad pad string format."));
             }
             if (!checkedOptions.RegexPattern.Contains("(") || !checkedOptions.RegexPattern.Contains(")"))
             {
                 throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                              "Option used in invalid context -- {0}", "regex pattern must contain a pair of '()'."));
             }
         }
         else
         {
             if (string.IsNullOrEmpty(checkedOptions.OutputPattern))
             {
                 throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                              "Option used in invalid context -- {0}", "bad output pattern."));
             }
         }
     }
 }
コード例 #3
0
ファイル: RenameCommandLine.cs プロジェクト: sclcwwl/Gimela
        public override void Execute()
        {
            base.Execute();

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

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

              Terminate();
        }
コード例 #4
0
ファイル: RenameCommandLine.cs プロジェクト: sclcwwl/Gimela
 private static void CheckOptions(RenameCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
       {
     if (string.IsNullOrEmpty(checkedOptions.RegexPattern))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a regex pattern."));
     }
     if (string.IsNullOrEmpty(checkedOptions.InputDirectory))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a input directory."));
     }
     if (!Directory.Exists(checkedOptions.InputDirectory))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "no such input directory."));
     }
     if (checkedOptions.IsSetPadString)
     {
       if (string.IsNullOrEmpty(checkedOptions.PadString))
       {
     throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
       "Option used in invalid context -- {0}", "bad pad string format."));
       }
       if (!checkedOptions.RegexPattern.Contains("(") || !checkedOptions.RegexPattern.Contains(")"))
       {
     throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
       "Option used in invalid context -- {0}", "regex pattern must contain a pair of '()'."));
       }
     }
     else
     {
       if (string.IsNullOrEmpty(checkedOptions.OutputPattern))
       {
     throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
       "Option used in invalid context -- {0}", "bad output pattern."));
       }
     }
       }
 }
コード例 #5
0
ファイル: RenameCommandLine.cs プロジェクト: sclcwwl/Gimela
        private static RenameCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
            throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
              "Option used in invalid context -- {0}", "must specify a option."));

              RenameCommandLineOptions targetOptions = new RenameCommandLineOptions();

              if (commandLineOptions.Arguments.Count >= 0)
              {
            foreach (var arg in commandLineOptions.Arguments.Keys)
            {
              RenameOptionType optionType = RenameOptions.GetOptionType(arg);
              if (optionType == RenameOptionType.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 RenameOptionType.RegexPattern:
              targetOptions.RegexPattern = commandLineOptions.Arguments[arg];
              break;
            case RenameOptionType.InputDirectory:
              targetOptions.InputDirectory = commandLineOptions.Arguments[arg];
              break;
            case RenameOptionType.Recursive:
              targetOptions.IsSetRecursive = true;
              break;
            case RenameOptionType.OutputPattern:
              targetOptions.OutputPattern = commandLineOptions.Arguments[arg];
              break;
            case RenameOptionType.Folder:
              targetOptions.IsSetFolder = true;
              break;
            case RenameOptionType.Exclude:
              targetOptions.Excludes.AddRange(
                commandLineOptions.Arguments[arg].Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList());
              break;
            case RenameOptionType.PadString:
              targetOptions.IsSetPadString = true;
              targetOptions.PadString = commandLineOptions.Arguments[arg];
              break;
            case RenameOptionType.Help:
              targetOptions.IsSetHelp = true;
              break;
            case RenameOptionType.Version:
              targetOptions.IsSetVersion = true;
              break;
              }
            }
              }

              return targetOptions;
        }
コード例 #6
0
        private static RenameCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Option used in invalid context -- {0}", "must specify a option."));
            }

            RenameCommandLineOptions targetOptions = new RenameCommandLineOptions();

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

                    case RenameOptionType.InputDirectory:
                        targetOptions.InputDirectory = commandLineOptions.Arguments[arg];
                        break;

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

                    case RenameOptionType.OutputPattern:
                        targetOptions.OutputPattern = commandLineOptions.Arguments[arg];
                        break;

                    case RenameOptionType.Folder:
                        targetOptions.IsSetFolder = true;
                        break;

                    case RenameOptionType.Exclude:
                        targetOptions.Excludes.AddRange(
                            commandLineOptions.Arguments[arg].Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList());
                        break;

                    case RenameOptionType.PadString:
                        targetOptions.IsSetPadString = true;
                        targetOptions.PadString      = commandLineOptions.Arguments[arg];
                        break;

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

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

            return(targetOptions);
        }