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)); }
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); }
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); }); }
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]; }); }
internal OptionValueCollection(OptionContext c) { this.c = c; }
public override Node VisitOption([NotNull] OptionContext context) { return(new WidgetOptionNode(context.Start, context.STRING().GetText().Trim('\"'))); }
protected abstract void OnParseComplete(OptionContext c);
protected override void OnParseComplete(OptionContext c) { _config.AdditionalCommandlineOptions[_dataKey] = c.OptionValues.ToList(); }
public void Initialize() { _optionContext = new OptionContext(); }
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); }
protected override void OnParseComplete(OptionContext c) { _action (c.OptionValues); }
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) );
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))); }
protected override void OnParseComplete(OptionContext c) { commands.showHelp = true; option?.InvokeOnParseComplete(c); }
protected override void OnParseComplete(OptionContext c) { action(c.OptionValues); }
/// <inheritdoc /> protected override void OnVisitation(OptionContext context) => Callback.Invoke();
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)); }
/// <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)); }
protected override void OnParseComplete(OptionContext c) { c.OptionSet.WriteOptionDescriptions(Console.Out); Environment.Exit(1); }
/// <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)); }
public void Invoke(OptionContext c) { OnParseComplete (c); c.OptionName = null; c.Option = null; c.OptionValues.Clear (); }
protected override void OnParseComplete(OptionContext c) { throw new NotImplementedException(); }
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); }
protected override void OnParseComplete (OptionContext c) { throw new NotImplementedException (); }
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; }