Exemplo n.º 1
0
        public bool AssignDefaults(ArgumentDictionary options)
        {
            base.VerifyRule();
            bool             flag             = false;
            StringCollection arguments        = options.GetArguments(string.Empty);
            StringCollection stringCollection = new StringCollection();

            if (arguments == null)
            {
                return(true);
            }
            foreach (string current in arguments)
            {
                if (base.Pattern.IsMatch(current))
                {
                    options.Add(base.Cswitch.Name, current);
                    stringCollection.Add(current);
                }
                else
                {
                    flag = true;
                }
            }
            foreach (string current2 in stringCollection)
            {
                arguments.Remove(current2);
            }
            return(!flag);
        }
Exemplo n.º 2
0
 public static void CheckRules(ArgumentDictionary arguments, CheckingRule[] rules)
 {
     for (int i = 0; i < rules.Length; i++)
     {
         CheckingRule checkingRule = rules[i];
         checkingRule.CheckRule(arguments);
     }
 }
Exemplo n.º 3
0
        public static ArgumentDictionary ParseCommand(string[] cmd, CommandSwitch[] switches, ResourceManager resources)
        {
            ArgumentDictionary argumentDictionary = new ArgumentDictionary(cmd.Length);

            for (int i = 0; i < cmd.Length; i++)
            {
                string text  = cmd[i];
                string text2 = text;
                if (text2[0] != '/' && text2[0] != '-')
                {
                    argumentDictionary.Add(string.Empty, text2);
                }
                else
                {
                    if (text2.Length == 1)
                    {
                        throw new CommandLineArgumentException(CommandParser.GetLocalizedText(resources, "CommandArgumentsMissingSwitch", "Invalid argument: switch missing."));
                    }
                    text2 = text2.Substring(1);
                    int num = text2.IndexOfAny(new char[]
                    {
                        ':',
                        '='
                    });
                    if (num == 0)
                    {
                        throw new CommandLineArgumentException(CommandParser.GetLocalizedText(resources, "CommandArgumentsSyntax", "Invalid argument: delimeter (':' or '=') may not start switch."));
                    }
                    string value;
                    if (num == -1)
                    {
                        value = string.Empty;
                    }
                    else
                    {
                        value = text2.Substring(num + 1);
                        text2 = text2.Substring(0, num);
                    }
                    CommandSwitch commandSwitch = CommandSwitch.FindSwitch(text2.ToLower(CultureInfo.InvariantCulture), switches);
                    if (commandSwitch == null)
                    {
                        string text3 = text2.ToLower(CultureInfo.InvariantCulture);
                        throw new CommandLineArgumentException(CommandParser.GetLocalizedText(resources, "CommandArgumentsUnknownSwitch", new string[]
                        {
                            text3
                        }, string.Format("Switch /{0} is an unknown switch", new string[]
                        {
                            text3
                        })));
                    }
                    argumentDictionary.Add(commandSwitch.Name, value);
                }
            }
            return(argumentDictionary);
        }
Exemplo n.º 4
0
 public static bool AssignUnknowns(ArgumentDictionary arguments, AssignmentRule[] rules)
 {
     for (int i = 0; i < rules.Length; i++)
     {
         AssignmentRule assignmentRule = rules[i];
         if (assignmentRule.AssignDefaults(arguments))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 5
0
        public void CheckRule(ArgumentDictionary options)
        {
            base.VerifyRule();
            string name = base.Cswitch.Name;

            if (!options.Contains(name))
            {
                if (this.switchRequired)
                {
                    throw new CommandLineException(this, "Switch \"" + name + "\" required but not provided");
                }
                return;
            }
            else
            {
                StringCollection arguments = options.GetArguments(name);
                if (base.Pattern.ToString() != ".*" && arguments.Count == 0)
                {
                    throw new CommandLineException(this, "Value[s] required for switch \"" + name + "\"");
                }
                if (arguments.Count > 1 && !this.multipleValuesAllowed)
                {
                    throw new CommandLineException(this, "Switch \"" + name + "\" may not be assigned multiple values");
                }
                foreach (string current in arguments)
                {
                    if (!base.Pattern.IsMatch(current))
                    {
                        throw new CommandLineException(this, string.Concat(new string[]
                        {
                            "Value \"",
                            current,
                            "\" for switch \"",
                            name,
                            "\" was invalid"
                        }));
                    }
                }
                return;
            }
        }