private static string GetArgumentName(Action action) { if (action == null) return null; if (action.OptionStrings.IsTrue()) return string.Format("({0})", string.Join("/", action.OptionStrings)); if (!string.IsNullOrWhiteSpace(action.MetaVariable)) return action.MetaVariable; if (action.HasDestination && action.HasValidDestination) return action.Destination; return null; }
public ArgumentActionConstraint(Action expected) : base(expected) { }
public void AreEqual(Action action1, Action action2) { Assert.That(action2, new ArgumentActionConstraint(action1)); }
private void HandleConflictWithResolve(Action action, IEnumerable<KeyValuePair<string, Action>> conflictingActions) { //remove all conflicting options foreach (var kv in conflictingActions) { kv.Value.OptionStrings.Remove(kv.Key); OptionStringActions.Remove(kv.Key); //if the option now has no option string, remove it from the container holding it if (!kv.Value.OptionStrings.Any()) kv.Value.Container.RemoveAction(kv.Value); } }
private void HandleConflictWithError(Action action, IEnumerable<KeyValuePair<string, Action>> conflictingActions) { List<string> conflictionOptions = conflictingActions.Select(it => it.Key).ToList(); string conflictString = string.Join(", ", conflictionOptions); if (conflictionOptions.Count == 1) throw new ParserException(string.Format("Confliction option string: {0}", conflictString)); throw new ParserException(string.Format("Confliction option strings: {0}", conflictString)); }
public void CheckConflict(Action action) { var conflOptionals = new List<KeyValuePair<string, Action>>(); foreach (string optionString in action.OptionStrings) { Action conflOptional; if (OptionStringActions.TryGetValue(optionString, out conflOptional)) conflOptionals.Add(new KeyValuePair<string, Action>(optionString, conflOptional)); } if (!conflOptionals.Any()) return; Action<Action, IEnumerable<KeyValuePair<string, Action>>> confictHandler = GetConflictHandler(); confictHandler(action, conflOptionals); }
public virtual void RemoveAction(Action action) { Actions.Remove(action); }
public virtual Action AddAction(Action action) { if (ReferenceEquals(action, null)) throw new ArgumentNullException("action"); CheckConflict(action); Actions.Add(action); action.Container = this; foreach (string optionString in action.OptionStrings) OptionStringActions[optionString] = action; if (!HasNegativeNumberOptionals.IsTrue() && action.OptionStrings.Any(optionString => NegativeNumberMatcher.IsMatch(optionString))) HasNegativeNumberOptionals.Add(true); return action; }
public UnknownParserException(Action action, string parserName) : base(action, string.Format("Unknown parser {0}", parserName)) { ParserName = parserName; }
public override void RemoveAction(Action action) { base.RemoveAction(action); GroupActions.Remove(action); }
public override Action AddAction(Action action) { Action res = base.AddAction(action); GroupActions.Add(res); return res; }
public InvalideChoiceException(Action action, object value) : base(action, string.Format("Invalid choice: {0}", value)) { Value = value; }
public override Action AddAction(Action action) { if (action.IsRequired) throw new ParserException("Mutually exclusive arguments must be optional"); return base.AddAction(action); }