コード例 #1
0
ファイル: Option.cs プロジェクト: perryofpeek/winCompare
 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);
	}
コード例 #3
0
		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
ファイル: Option.cs プロジェクト: perryofpeek/winCompare
 protected abstract void OnParseComplete(OptionContext c);
コード例 #6
0
ファイル: OptionTest.cs プロジェクト: emanueldejanu/ycup
 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);
 }