コード例 #1
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();
        }
コード例 #2
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);
        }