コード例 #1
0
        public Arguments ProcessArgs(string[] originalArgs, Func <int, string[]> exitFunc)
        {
            var args = NormalizeArgs(originalArgs);

            try {
                int  argc           = args.Length;
                bool foundNonOption = false;
                for (int i = 0; i < argc; i++)
                {
                    string arg     = args[i];
                    string nextArg = (i + 1 < argc) ? nextArg = args[i + 1] : null;

                    if (!string.IsNullOrWhiteSpace(arg))
                    {
                        if (MaybeAnOption(arg) && !foundNonOption)
                        {
                            bool OptionWasProcessed = false;
                            foreach (OptionDetails option in _list)
                            {
                                OptionProcessingResult result = option.ProcessArgument(arg, nextArg);
                                if (result != OptionProcessingResult.NotThisOption)
                                {
                                    OptionWasProcessed = true;
                                    if (result == OptionProcessingResult.OptionConsumedParameter)
                                    {
                                        i++;
                                    }
                                    break;
                                }
                            }
                            if (!OptionWasProcessed)
                            {
                                WriteLine(_Format("Invalid argument: '{0}'", arg));
                                DoHelp();
                                exitFunc(1);
                                return(null);
                            }
                        }
                        else
                        {
                            ProcessNonOption(arg);
                            if (_stopOnFirstNonOption && !foundNonOption)
                            {
                                foundNonOption = true;
                            }
                        }
                    }
                }

                foreach (OptionDetails option in _list)
                {
                    option.TransferValues();
                }

                foreach (string argument in _argumentsTail)
                {
                    ProcessNonOption(argument);
                }

                return(new Arguments(_arguments));
            } catch (Exception ex) {
                WriteLine(_Format("Exception: {0}", ex));
                exitFunc(1);
                return(null);
            }
        }
コード例 #2
0
        public string[] ProcessArgs(string[] args)
        {
            this.list.Sort();
            args = this.NormalizeArgs(args);
            try
            {
                int num1 = args.Length;
                for (int num2 = 0; num2 < num1; num2++)
                {
                    string text1;
                    string text2 = args[num2];
                    if ((num2 + 1) < num1)
                    {
                        text1 = args[num2 + 1];
                    }
                    else
                    {
                        text1 = null;
                    }
                    bool flag1 = false;
                    if ((text2.Length <= 1) || (!text2.StartsWith("-", StringComparison.Ordinal) && !text2.StartsWith("/", StringComparison.Ordinal)))
                    {
                        goto Label_00DA;
                    }
                    IEnumerator enumerator1 = this.list.GetEnumerator();
Label_0078:
                    try
                    {
                        if (enumerator1.MoveNext())
                        {
                            OptionDetails          details1 = (OptionDetails)enumerator1.Current;
                            OptionProcessingResult result1  = details1.ProcessArgument(text2, text1);
                            if (result1 == OptionProcessingResult.NotThisOption)
                            {
                                goto Label_0078;
                            }
                            flag1 = true;
                            if (result1 == OptionProcessingResult.OptionConsumedParameter)
                            {
                                num2++;
                            }
                        }
                    }
                    finally
                    {
                        IDisposable disposable1 = enumerator1 as IDisposable;
                        if (disposable1 != null)
                        {
                            disposable1.Dispose();
                        }
                    }
Label_00DA:
                    if (!flag1)
                    {
                        this.ProcessNonOption(text2);
                    }
                }
                IEnumerator enumerator2 = this.list.GetEnumerator();
Label_0102:
                try
                {
                    if (enumerator2.MoveNext())
                    {
                        OptionDetails details2 = (OptionDetails)enumerator2.Current;
                        details2.TransferValues();
                        goto Label_0102;
                    }
                }
                finally
                {
                    IDisposable disposable2 = enumerator2 as IDisposable;
                    if (disposable2 != null)
                    {
                        disposable2.Dispose();
                    }
                }
                IEnumerator enumerator3 = this.argumentsTail.GetEnumerator();
Label_0151:
                try
                {
                    if (enumerator3.MoveNext())
                    {
                        string text3 = (string)enumerator3.Current;
                        this.ProcessNonOption(text3);
                        goto Label_0151;
                    }
                }
                finally
                {
                    IDisposable disposable3 = enumerator3 as IDisposable;
                    if (disposable3 != null)
                    {
                        disposable3.Dispose();
                    }
                }
                return((string[])this.arguments.ToArray(typeof(string)));
            }
            catch (Exception exception1)
            {
                Console.WriteLine(exception1.ToString());
                Environment.Exit(1);
            }
            return(null);
        }
コード例 #3
0
ファイル: OptionList_1.cs プロジェクト: tsgouros/wv
        public string[] ProcessArgs(string[] args)
        {
            string arg;
            string nextArg;
            bool   OptionWasProcessed;

            list.Sort();

            OptionDetails.LinkAlternatesInsideList(list);

            args = NormalizeArgs(args);

            try {
                int argc = args.Length;
                for (int i = 0; i < argc; i++)
                {
                    arg = args[i];
                    if (i + 1 < argc)
                    {
                        nextArg = args[i + 1];
                    }
                    else
                    {
                        nextArg = null;
                    }

                    OptionWasProcessed = false;

                    if (arg.Length > 1 && (arg.StartsWith("-") || arg.StartsWith("/")))
                    {
                        foreach (OptionDetails option in list)
                        {
                            OptionProcessingResult result = option.ProcessArgument(arg, nextArg);
                            if (result != OptionProcessingResult.NotThisOption)
                            {
                                OptionWasProcessed = true;
                                if (result == OptionProcessingResult.OptionConsumedParameter)
                                {
                                    i++;
                                }
                                break;
                            }
                        }
                    }

                    if (!OptionWasProcessed)
                    {
                        ProcessNonOption(arg);
                    }
                }

                foreach (OptionDetails option in list)
                {
                    option.TransferValues();
                }

                foreach (string argument in argumentsTail)
                {
                    ProcessNonOption(argument);
                }

                return((string[])arguments.ToArray(typeof(string)));
            } catch (Exception ex) {
                System.Console.WriteLine(ex.ToString());
                //System.Environment.Exit(1);
                throw;
            }
        }