Example #1
0
 protected override void OnParseComplete(OptionContext c)
 {
     // OptionValues is re-used, need to create a local copy here
     // also, OptionValueType.None causes the option name to be passed as value, that should be removed
     var args = this.OptionValueType == Utils.OptionValueType.None
         ? new string[0]
         : c.OptionValues.SelectMany(a => a.Split(new char[] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries)).ToArray();
     _config.AdditionalCommandlineActions.Add(scope => InvokeCore(scope, args));
 }
Example #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)
            {
                nextOption = Contains (n) ? this [n] : null;
                newOption = f + n + (v != null ? s + v : "");
            }

            if (c.Option != null)
            {
                // Prevent --a --b
                if (c.Option != null && haveParts)
                {
                    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);
        }
Example #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]; Console.Write(ignore); });
     c.Option = p[0];
     Assert.That (()=>c.OptionValues[2], Throws.InstanceOf<ArgumentOutOfRangeException>());
     c.OptionName = "-a";
     Utils.AssertException(typeof(OptionException),
             "Missing required value for option '-a'.",
             c, v => { string ignore = v.OptionValues[0]; Console.Write(ignore); });
 }
Example #4
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),
					"Specified argument was out of the range of valid values.\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]; });
		}
Example #5
0
 internal OptionValueCollection(OptionContext c)
 {
     this.c = c;
 }
 public override Node VisitOption([NotNull] OptionContext context)
 {
     return(new WidgetOptionNode(context.Start, context.STRING().GetText().Trim('\"')));
 }
Example #7
0
 protected abstract void OnParseComplete(OptionContext c);
Example #8
0
 protected override void OnParseComplete(OptionContext c)
 {
     _config.AdditionalCommandlineOptions[_dataKey] = c.OptionValues.ToList();
 }
 public void Initialize()
 {
     _optionContext = new OptionContext();
 }
Example #10
0
        protected virtual bool Parse(string argument, OptionContext c)
        {
            if (c.Option != null)
            {
                ParseValue(argument, c);
                return(true);
            }

            string f, n, s, v;

            if (!GetOptionParts(argument, out f, out n, out s, out v))
            {
                //unrecognised option!
                if (UnrecognizedOptions == null)
                {
                    UnrecognizedOptions = new List <string>();
                }
                UnrecognizedOptions.Add(argument);

                return(false);
            }
            Option p;

            if (Contains(n))
            {
                p            = this [n];
                c.OptionName = f + n;
                c.Option     = p;
                switch (p.OptionValueType)
                {
                case OptionValueType.None:
                    c.OptionValues.Add(n);
                    c.Option.Invoke(c);
                    break;

                case OptionValueType.Optional:
                case OptionValueType.Required:
                    ParseValue(v, c);
                    break;
                }
                return(true);
            }
            // no match; is it a bool option?
            if (ParseBool(argument, n, c))
            {
                return(true);
            }
            // is it a bundled option?
            if (ParseBundledValue(f, string.Concat(n + s + v), c))
            {
                return(true);
            }


            //unrecognised option!
            if (UnrecognizedOptions == null)
            {
                UnrecognizedOptions = new List <string>();
            }
            UnrecognizedOptions.Add(argument);

            return(false);
        }
Example #11
0
 protected override void OnParseComplete(OptionContext c)
 {
     _action (c.OptionValues);
 }
Example #12
0
 protected override void OnParseComplete(OptionContext c)
 {
     throw new NotSupportedException("Category.OnParseComplete should not be invoked.");
 }
 /// <inheritdoc />
 protected override void OnVisitation(OptionContext context) => Callback.Invoke(
     Parse <TTarget>(context.Parameters[0], context)
     );
Example #14
0
 protected override bool Parse(string option, OptionContext c)
 {
     return(c.Option != null?base.Parse(option, c) : (!GetOptionParts(option, out var f, out var n, out var s, out var v) ? base.Parse(option, c) : base.Parse(f + n.ToLower() + (v != null && s != null ? s + v : ""), c)));
 }
Example #15
0
        protected override void OnParseComplete(OptionContext c)
        {
            commands.showHelp = true;

            option?.InvokeOnParseComplete(c);
        }
Example #16
0
 protected abstract void OnParseComplete(OptionContext c);
Example #17
0
 protected override void OnParseComplete(OptionContext c)
 {
     action(c.OptionValues);
 }
Example #18
0
 /// <inheritdoc />
 protected override void OnVisitation(OptionContext context) => Callback.Invoke();
Example #19
0
 protected override void OnParseComplete(OptionContext c)
 {
     Console.WriteLine("# Parsed {0}; Value={1}; Index={2}",
                       c.OptionName, c.OptionValues [0] ?? "<null>", c.OptionIndex);
     action(Parse <T> (c.OptionValues [0], c));
 }
Example #20
0
 /// <summary>
 /// Returns a Slinq that enumerates the specified option.
 ///
 /// Slinqs created by this method do not support element removal.
 /// </summary>
 public static Slinq <T, OptionContext <T> > Slinq <T>(this Option <T> option)
 {
     return(OptionContext <T> .Slinq(option));
 }
Example #21
0
 protected override void OnParseComplete(OptionContext c)
 {
     c.OptionSet.WriteOptionDescriptions(Console.Out);
     Environment.Exit(1);
 }
Example #22
0
 /// <summary>
 /// Returns a Slinq that repeats the specified value.
 ///
 /// Slinqs created by this method do not support element removal.
 /// </summary>
 public static Slinq <T, OptionContext <T> > Repeat <T>(T value)
 {
     return(OptionContext <T> .Repeat(value));
 }
Example #23
0
 public void Invoke(OptionContext c)
 {
     OnParseComplete (c);
       c.OptionName = null;
       c.Option = null;
       c.OptionValues.Clear ();
 }
Example #24
0
 protected override void OnParseComplete(OptionContext c)
 {
     throw new NotImplementedException();
 }
Example #25
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;
 }
 protected override void OnParseComplete(OptionContext c)
 {
     _action(true);
 }
Example #27
0
		protected override void OnParseComplete (OptionContext c)
		{
			throw new NotImplementedException ();
		}
Example #28
0
        protected override OptionControlList OnSetupOptions(OptionContext optContext)
        {
            OptionInt32Slider cellSize = new OptionInt32Slider(OptionNames.CellSize, optContext, 10, 10, 100);
            cellSize.NumericUnit = new NumericUnit("px\u00B2");
            OptionInt32Slider groupSize = new OptionInt32Slider(OptionNames.GroupSize, optContext, 5, 1, 10);
            groupSize.NumericUnit = new NumericUnit("\u00B2");
            OptionInt32Slider clusterSize = new OptionInt32Slider(OptionNames.ClusterSize, optContext, 2, 1, 10);
            clusterSize.NumericUnit = new NumericUnit("\u00B2");
            Color mixedColor = Color.FromArgb((EnvironmentParameters.PrimaryColor.A + EnvironmentParameters.SecondaryColor.A) / 2, (EnvironmentParameters.PrimaryColor.R + EnvironmentParameters.SecondaryColor.R) / 2,
                (EnvironmentParameters.PrimaryColor.G + EnvironmentParameters.SecondaryColor.G) / 2, (EnvironmentParameters.PrimaryColor.B + EnvironmentParameters.SecondaryColor.B) / 2);

            OptionControlList options = new OptionControlList
            {
                new OptionEnumRadioButtons<GraphTypeEnum>(OptionNames.GraphType, optContext, GraphTypeEnum.Standard),
                cellSize,
                groupSize,
                clusterSize,
                new OptionPanelBox(OptionNames.LineStylesBox, optContext)
                {
                    new OptionEnumRadioButtons<CellLineStyleEnum>(OptionNames.CellLineStyle, optContext, CellLineStyleEnum.Dotted)
                    {
                        Packed = true
                    },
                    new OptionEnumRadioButtons<GroupLineStyleEnum>(OptionNames.GroupLineStyle, optContext, GroupLineStyleEnum.Dashed)
                    {
                        Packed = true
                    },
                    new OptionEnumRadioButtons<ClusterLineStyleEnum>(OptionNames.ClusterLineStyle, optContext, ClusterLineStyleEnum.Solid)
                    {
                        Packed = true
                    }
                },
                new OptionPanelPagesAsTabs(OptionNames.ColorTabs, optContext)
                {
                    new OptionPanelPage(OptionNames.CellColorTab, optContext)
                    {
                        new OptionEnumRadioButtons<CellColorEnum>(OptionNames.CellColor, optContext, CellColorEnum.Custom)
                        {
                            Packed = true
                        },
                        new OptionColorWheel(OptionNames.CellColorWheel, optContext, EnvironmentParameters.PrimaryColor, ColorWheelEnum.AddAlpha | ColorWheelEnum.AddPalette),
                    },
                    new OptionPanelPage(OptionNames.GroupColorTab, optContext)
                    {
                        new OptionEnumRadioButtons<GroupColorEnum>(OptionNames.GroupColor, optContext, GroupColorEnum.CellColor)
                        {
                            Packed = true
                        },
                        new OptionColorWheel(OptionNames.GroupColorWheel, optContext, EnvironmentParameters.PrimaryColor, ColorWheelEnum.AddAlpha | ColorWheelEnum.AddPalette),
                    },
                    new OptionPanelPage(OptionNames.ClusterColorTab, optContext)
                    {
                        new OptionEnumRadioButtons<ClusterColorEnum>(OptionNames.ClusterColor, optContext, ClusterColorEnum.CellColor)
                        {
                            Packed = true
                        },
                        new OptionColorWheel(OptionNames.ClusterColorWheel, optContext, EnvironmentParameters.PrimaryColor, ColorWheelEnum.AddAlpha | ColorWheelEnum.AddPalette),
                    },
                    new OptionPanelPage(OptionNames.IsoVerColorTab, optContext)
                    {
                        new OptionEnumRadioButtons<IsoVerColorEnum>(OptionNames.IsoVerColor, optContext, IsoVerColorEnum.Custom)
                        {
                            Packed = true
                        },
                        new OptionColorWheel(OptionNames.IsoVerColorWheel, optContext, mixedColor, ColorWheelEnum.AddAlpha | ColorWheelEnum.AddPalette)
                    },
                    new OptionPanelPage(OptionNames.BgColorTab, optContext)
                    {
                        new OptionEnumRadioButtons<BgColorEnum>(OptionNames.BgColor, optContext, BgColorEnum.Custom)
                        {
                            Packed = true
                        },
                        new OptionColorWheel(OptionNames.BgColorWheel, optContext, EnvironmentParameters.SecondaryColor, ColorWheelEnum.AddAlpha | ColorWheelEnum.AddPalette)
                    }
                }
            };
            return options;
        }