示例#1
0
        public override void Execute()
        {
            base.Execute();

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

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

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

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

            AddTextCommandLineOptions targetOptions = new AddTextCommandLineOptions();

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

                    case AddTextOptionType.Text:
                        targetOptions.Text = commandLineOptions.Arguments[arg];
                        break;

                    case AddTextOptionType.FromFile:
                        targetOptions.IsSetFromFile = true;
                        targetOptions.FromFile      = commandLineOptions.Arguments[arg];
                        break;

                    case AddTextOptionType.Top:
                        targetOptions.IsSetTop = true;
                        break;

                    case AddTextOptionType.Bottom:
                        targetOptions.IsSetBottom = true;
                        break;

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

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

            return(targetOptions);
        }