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]; }); }
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 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); }
protected override void OnParseComplete(OptionContext c) { throw new NotSupportedException("CommandOption.OnParseComplete should not be invoked."); }
protected override void OnParseComplete(OptionContext c) { action(c.OptionValues); }
private bool ParseBool(string option, string n, OptionContext c) { Option p; string rn; if (n.Length >= 1 && (n[^ 1] == '+' || n[^ 1] == '-') &&
protected override void OnParseComplete(OptionContext c) { throw new NotSupportedException($"{nameof(Category)}.{nameof(OnParseComplete)} should not be invoked."); }
public OptionValueCollection(OptionContext c) { C = c; }
protected abstract void OnParseComplete(OptionContext c);
internal OptionValueCollection(OptionContext c) { _c = c; }
public void InvokeOnParseComplete(OptionContext c) { OnParseComplete(c); }
protected override void OnParseComplete(OptionContext c) { Commands.ShowHelp = true; Option?.InvokeOnParseComplete(c); }
protected override void OnParseComplete(OptionContext c) { throw new NotImplementedException (); }