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

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

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

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

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

            JoinCommandLineOptions targetOptions = new JoinCommandLineOptions();

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

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

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

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

            return(targetOptions);
        }
 private static void CheckOptions(JoinCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
     {
         if (string.IsNullOrEmpty(checkedOptions.OutputFile))
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a output file path."));
         }
         if (checkedOptions.InputFiles.Count <= 1)
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "should specify two or more input files."));
         }
     }
 }
Example #4
0
        public override void Execute()
        {
            base.Execute();

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

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

              Terminate();
        }
Example #5
0
 private static void CheckOptions(JoinCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
       {
     if (string.IsNullOrEmpty(checkedOptions.OutputFile))
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "must specify a output file path."));
     }
     if (checkedOptions.InputFiles.Count <= 1)
     {
       throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
     "Option used in invalid context -- {0}", "should specify two or more input files."));
     }
       }
 }
Example #6
0
        private static JoinCommandLineOptions ParseOptions(CommandLineOptions commandLineOptions)
        {
            if (commandLineOptions == null)
            throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
              "Option used in invalid context -- {0}", "must specify a option."));

              JoinCommandLineOptions targetOptions = new JoinCommandLineOptions();

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

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

              return targetOptions;
        }