예제 #1
0
 public void Invoke(OptionContext c)
 {
     OnParseComplete (c);
     c.OptionName  = null;
     c.OptionValue = null;
     c.Option      = null;
 }
예제 #2
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.AssertException (typeof(InvalidOperationException),
					"OptionContext.Option is null.",
					c, v => { string ignore = v.OptionValues [0]; });
			c.Option = p [0];
			Utils.AssertException (typeof(ArgumentOutOfRangeException),
					"Argument is out of range.\nParameter name: index",
					c, v => { string ignore = v.OptionValues [2]; });
			c.OptionName = "-a";
			Utils.AssertException (typeof(OptionException),
					"Missing required value for option '-a'.",
					c, v => { string ignore = v.OptionValues [0]; });
		}
예제 #4
0
	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;
	}
예제 #5
0
 protected abstract void OnParseComplete(OptionContext c);
예제 #6
0
 protected override void OnParseComplete(OptionContext c)
 {
     throw new NotImplementedException ();
 }
예제 #7
0
 protected override void OnParseComplete(OptionContext c)
 {
     action(c.OptionValues);
 }
예제 #8
0
 protected abstract void OnParseComplete(OptionContext c);
예제 #9
0
 internal OptionValueCollection(OptionContext c)
 {
     this.c = c;
 }
예제 #10
0
 internal OptionValueCollection(OptionContext context)
 {
     _context = context;
 }
예제 #11
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 (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);
                }
                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 != null)
            {
                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));
        }
예제 #12
0
 protected override void OnParseComplete(OptionContext c) {
     action(c.OptionValues);
 }