public override bool Parse(ArgumentParser parser, string key, string[] values, ref int index)
 {
     if ((index + 1) < values.Length)
     {
         string str  = values[index + 1];
         string str2 = str;
         if (str.StartsWith("-") || str.StartsWith("+"))
         {
             str2 = ConsoleChars.GetMathsChar(ConsoleMathsChars.PlusMinus) + key.Substring(1);
         }
         ArgumentKey    outKey = null;
         IArgumentValue forKey = null;
         if (parser.ContainsKey(str))
         {
             forKey = parser.GetForKey(str, out outKey);
         }
         else if (!str2.Equals(str) && parser.ContainsKey(str2))
         {
             forKey = parser.GetForKey(str2, out outKey);
         }
         if ((outKey == null) || (forKey == null))
         {
             this.SetValue(values[index + 1]);
             index++;
         }
     }
     return(false);
 }
Example #2
0
        public void Parse(string[] args)
        {
            ConsoleColorState colorState = RugConsole.ColorState;

            try
            {
                if (args.Length > 0)
                {
                    int num = 0;
                    StringListArgument firstArgument = null;
                    if (args[0] == "/?")
                    {
                        if (args.Length == 1)
                        {
                            this.WriteLongArgumentsUsage();
                        }
                        else
                        {
                            this.WriteShortArgumentsUsage();
                        }
                        this.m_HelpMode = true;
                        num++;
                    }
                    else if (args[0] == "/??")
                    {
                        this.WriteApplicationAboutToConsole(true);
                        this.m_HelpMode = true;
                        num++;
                    }
                    else
                    {
                        if (args[0].Equals("/?D", StringComparison.CurrentCultureIgnoreCase))
                        {
                            string str;
                            if (args.Length > 1)
                            {
                                str = args[1];
                            }
                            else
                            {
                                str = Path.Combine(Environment.CurrentDirectory, this.m_AppName + " Documentation.txt");
                            }
                            this.WriteApplicationDocumentationToPath(str);
                            this.m_HelpMode = true;
                            return;
                        }
                        if (this.m_FirstArgument != null)
                        {
                            this.m_FirstArgument.SetValue(args[0]);
                            this.m_FirstArgument.Defined = true;
                            if (this.m_FirstArgument is StringListArgument)
                            {
                                firstArgument = this.m_FirstArgument as StringListArgument;
                            }
                            num++;
                        }
                    }
                    int index  = num;
                    int length = args.Length;
                    while (index < length)
                    {
                        string str2 = args[index];
                        string str3 = str2;
                        if (str2.StartsWith("-") || str2.StartsWith("+"))
                        {
                            str3 = ConsoleChars.GetMathsChar(ConsoleMathsChars.PlusMinus) + str2.Substring(1);
                        }
                        ArgumentKey    outKey = null;
                        IArgumentValue forKey = null;
                        if (this.ContainsKey(str2))
                        {
                            forKey = this.GetForKey(str2, out outKey);
                        }
                        else if (!str3.Equals(str2) && this.ContainsKey(str3))
                        {
                            forKey = this.GetForKey(str3, out outKey);
                        }
                        if ((outKey != null) && (forKey != null))
                        {
                            if (this.m_HelpMode)
                            {
                                this.WriteIndividualHelpToConsole(outKey);
                            }
                            else
                            {
                                forKey.Defined = true;
                                if (forKey.Parse(this, str2, args, ref index))
                                {
                                    firstArgument = forKey as StringListArgument;
                                }
                                else
                                {
                                    firstArgument = null;
                                }
                            }
                        }
                        else if ((firstArgument != null) && !this.m_HelpMode)
                        {
                            firstArgument.SetValue(str2);
                        }
                        else
                        {
                            if ((this.m_DefaultArgument == null) || this.m_HelpMode)
                            {
                                throw new Exception(string.Format(Strings.ArgumentParser_InvalidSwitch, str2));
                            }
                            this.m_DefaultArgument.SetValue(str2);
                        }
                        index++;
                    }
                }
            }
            finally
            {
                RugConsole.ColorState = colorState;
            }
        }