示例#1
0
        protected override bool Parse(string option, OptionContext c)
        {
            string f, n, s, v;
              bool haveParts = GetOptionParts(option, out f, out n, out s, out v);
              Option nextOption = null;
              string newOption = option;

              if (haveParts)
              {
            string nl = n.ToLower();
            nextOption = Contains(nl) ? this[nl] : null;
            newOption = f + n.ToLower() + (v != null ? s + v : "");
              }

              if (c.Option != null)
              {
            // Prevent --a --b
            if (c.Option != null && haveParts)
            {
              if (nextOption == null)
              {
            // ignore
              }
              else
            throw new OptionException(
                string.Format("Found option `{0}' as value for option `{1}'.",
                    option, c.OptionName), c.OptionName);
            }

            // have a option w/ required value; try to concat values.
            if (AppendValue(option, c))
            {
              if (!option.EndsWith("\\") &&
                  c.Option.MaxValueCount == c.OptionValues.Count)
              {
            c.Option.Invoke(c);
              }
              return true;
            }
            else
              base.Parse(newOption, c);
              }

              if (!haveParts || v == null)
              {
            // Not an option; let base handle as a non-option argument.
            return base.Parse(newOption, c);
              }

              if (nextOption.OptionValueType != OptionValueType.None &&
              v.EndsWith("\\"))
              {
            c.Option = nextOption;
            c.OptionValues.Add(v);
            c.OptionName = f + n;
            return true;
              }

              return base.Parse(newOption, c);
        }
        public void Exceptions()
        {
            OptionSet p = new OptionSet()
                {
                    {"a=", v => {/* ignore */}},
                };

            OptionContext c = new OptionContext(p);
            Utils.Assert<InvalidOperationException>("OptionContext.Option is null.", () => { string ignore = c.OptionValues[0]; });

            c.Option = p[0];
            Utils.AssertArgumentOutOfRangeException("index", () => { string ignore = c.OptionValues[2]; });

            c.OptionName = "-a";
            Utils.Assert<OptionException>("Missing required value for option '-a'.", () => { string ignore = c.OptionValues[0]; });
        }
示例#3
0
文件: subclass.cs 项目: nlhepler/mono
	private bool AppendValue (string value, OptionContext c)
	{
		bool added = false;
		string[] seps = c.Option.GetValueSeparators ();
		foreach (var o in seps.Length != 0
				? value.Split (seps, StringSplitOptions.None)
				: new string[]{value}) {
			int idx = c.OptionValues.Count-1;
			if (idx == -1 || !c.OptionValues [idx].EndsWith ("\\")) {
				c.OptionValues.Add (o);
				added = true;
			}
			else {
				c.OptionValues [idx] += value;
				added = true;
			}
		}
		return added;
	}
示例#4
0
文件: repl.cs 项目: abock/csi
        protected override bool Parse(string option, OptionContext context)
        {
            if (ScriptArguments != null) {
                if (ScriptFile == null) {
                    ScriptFile = option;
                } else {
                    ScriptArguments.Add (option);
                }
                return true;
            } else if (option == "-s" || option == "/s" ||
                option == "--script" || option == "/script") {
                ScriptArguments = new List<string> ();
            }

            return base.Parse (option, context);
        }
            protected override bool Parse(string argument, OptionContext c)
            {
                if (_caseSensitiveParsing)
                    return base.Parse(argument, c);

                string transformedArgument = c.Option == null ? argument.ToLower() : argument;
                return base.Parse(transformedArgument, c);
            }
示例#6
0
 protected override void OnParseComplete(OptionContext c)
 {
     throw new NotSupportedException("CommandOption.OnParseComplete should not be invoked.");
 }
示例#7
0
 protected override void OnParseComplete(OptionContext c)
 {
     action(c.OptionValues);
 }
示例#8
0
        private bool ParseBool(string option, string n, OptionContext c)
        {
            Option p;
            string rn;

            if (n.Length >= 1 && (n[^ 1] == '+' || n[^ 1] == '-') &&
示例#9
0
 protected override void OnParseComplete(OptionContext c)
 {
     throw new NotSupportedException($"{nameof(Category)}.{nameof(OnParseComplete)} should not be invoked.");
 }
示例#10
0
 public OptionValueCollection(OptionContext c)
 {
     C = c;
 }
示例#11
0
 protected abstract void OnParseComplete(OptionContext c);
 internal OptionValueCollection(OptionContext c)
 {
     _c = c;
 }
示例#13
0
 public void InvokeOnParseComplete(OptionContext c)
 {
     OnParseComplete(c);
 }
示例#14
0
        protected override void OnParseComplete(OptionContext c)
        {
            Commands.ShowHelp = true;

            Option?.InvokeOnParseComplete(c);
        }
 protected override void OnParseComplete(OptionContext c)
 {
     throw new NotImplementedException ();
 }