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

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

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

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

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

            MoveDateCommandLineOptions targetOptions = new MoveDateCommandLineOptions();

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

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

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

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

            return(targetOptions);
        }
Ejemplo n.º 3
0
 private static void CheckOptions(MoveDateCommandLineOptions 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."));
         }
     }
 }
Ejemplo n.º 4
0
        public override void Execute()
        {
            base.Execute();

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

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

            Terminate();
        }
Ejemplo n.º 5
0
 private static void CheckOptions(MoveDateCommandLineOptions 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."));
         }
     }
 }
Ejemplo n.º 6
0
        private static MoveDateCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                  "Option used in invalid context -- {0}", "must specify a option."));

            MoveDateCommandLineOptions targetOptions = new MoveDateCommandLineOptions();

            if (commandLineOptions.Arguments.Count >= 0)
            {
                foreach (var arg in commandLineOptions.Arguments.Keys)
                {
                    MoveDateOptionType optionType = MoveDateOptions.GetOptionType(arg);
                    if (optionType == MoveDateOptionType.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 MoveDateOptionType.RegexPattern:
                            targetOptions.RegexPattern = commandLineOptions.Arguments[arg];
                            break;
                        case MoveDateOptionType.InputDirectory:
                            targetOptions.InputDirectory = commandLineOptions.Arguments[arg];
                            break;
                        case MoveDateOptionType.Help:
                            targetOptions.IsSetHelp = true;
                            break;
                        case MoveDateOptionType.Version:
                            targetOptions.IsSetVersion = true;
                            break;
                    }
                }
            }

            return targetOptions;
        }